Skip to content

Commit 303a584

Browse files
committed
Fix line endings
1 parent 9f88bd9 commit 303a584

File tree

5 files changed

+278
-278
lines changed

5 files changed

+278
-278
lines changed

discord/commands/permissions.py

Lines changed: 110 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -1,110 +1,110 @@
1-
"""
2-
The MIT License (MIT)
3-
4-
Copyright (c) 2015-2021 Rapptz
5-
Copyright (c) 2021-present Pycord Development
6-
7-
Permission is hereby granted, free of charge, to any person obtaining a
8-
copy of this software and associated documentation files (the "Software"),
9-
to deal in the Software without restriction, including without limitation
10-
the rights to use, copy, modify, merge, publish, distribute, sublicense,
11-
and/or sell copies of the Software, and to permit persons to whom the
12-
Software is furnished to do so, subject to the following conditions:
13-
14-
The above copyright notice and this permission notice shall be included in
15-
all copies or substantial portions of the Software.
16-
17-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18-
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22-
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23-
DEALINGS IN THE SOFTWARE.
24-
"""
25-
26-
from typing import Callable
27-
28-
from ..permissions import Permissions
29-
from .core import ApplicationCommand
30-
31-
__all__ = (
32-
"default_permissions",
33-
"guild_only",
34-
)
35-
36-
37-
def default_permissions(**perms: bool) -> Callable:
38-
"""A decorator that limits the usage of a slash command to members with certain
39-
permissions.
40-
41-
The permissions passed in must be exactly like the properties shown under
42-
:class:`.discord.Permissions`.
43-
44-
.. note::
45-
These permissions can be updated by server administrators per-guild. As such, these are only "defaults", as the
46-
name suggests. If you want to make sure that a user **always** has the specified permissions regardless, you
47-
should use an internal check such as :func:`~.ext.commands.has_permissions`.
48-
49-
Parameters
50-
----------
51-
**perms: Dict[:class:`str`, :class:`bool`]
52-
An argument list of permissions to check for.
53-
54-
Example
55-
-------
56-
57-
.. code-block:: python3
58-
59-
from discord import default_permissions
60-
61-
@bot.slash_command()
62-
@default_permissions(manage_messages=True)
63-
async def test(ctx):
64-
await ctx.respond('You can manage messages.')
65-
"""
66-
67-
invalid = set(perms) - set(Permissions.VALID_FLAGS)
68-
if invalid:
69-
raise TypeError(f"Invalid permission(s): {', '.join(invalid)}")
70-
71-
def inner(command: Callable):
72-
if isinstance(command, ApplicationCommand):
73-
if command.parent is not None:
74-
raise RuntimeError(
75-
"Permission restrictions can only be set on top-level commands"
76-
)
77-
command.default_member_permissions = Permissions(**perms)
78-
else:
79-
command.__default_member_permissions__ = Permissions(**perms)
80-
return command
81-
82-
return inner
83-
84-
85-
def guild_only() -> Callable:
86-
"""A decorator that limits the usage of a slash command to guild contexts.
87-
The command won't be able to be used in private message channels.
88-
89-
Example
90-
-------
91-
92-
.. code-block:: python3
93-
94-
from discord import guild_only
95-
96-
@bot.slash_command()
97-
@guild_only()
98-
async def test(ctx):
99-
await ctx.respond("You're in a guild.")
100-
"""
101-
102-
def inner(command: Callable):
103-
if isinstance(command, ApplicationCommand):
104-
command.guild_only = True
105-
else:
106-
command.__guild_only__ = True
107-
108-
return command
109-
110-
return inner
1+
"""
2+
The MIT License (MIT)
3+
4+
Copyright (c) 2015-2021 Rapptz
5+
Copyright (c) 2021-present Pycord Development
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a
8+
copy of this software and associated documentation files (the "Software"),
9+
to deal in the Software without restriction, including without limitation
10+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
11+
and/or sell copies of the Software, and to permit persons to whom the
12+
Software is furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in
15+
all copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23+
DEALINGS IN THE SOFTWARE.
24+
"""
25+
26+
from typing import Callable
27+
28+
from ..permissions import Permissions
29+
from .core import ApplicationCommand
30+
31+
__all__ = (
32+
"default_permissions",
33+
"guild_only",
34+
)
35+
36+
37+
def default_permissions(**perms: bool) -> Callable:
38+
"""A decorator that limits the usage of a slash command to members with certain
39+
permissions.
40+
41+
The permissions passed in must be exactly like the properties shown under
42+
:class:`.discord.Permissions`.
43+
44+
.. note::
45+
These permissions can be updated by server administrators per-guild. As such, these are only "defaults", as the
46+
name suggests. If you want to make sure that a user **always** has the specified permissions regardless, you
47+
should use an internal check such as :func:`~.ext.commands.has_permissions`.
48+
49+
Parameters
50+
----------
51+
**perms: Dict[:class:`str`, :class:`bool`]
52+
An argument list of permissions to check for.
53+
54+
Example
55+
-------
56+
57+
.. code-block:: python3
58+
59+
from discord import default_permissions
60+
61+
@bot.slash_command()
62+
@default_permissions(manage_messages=True)
63+
async def test(ctx):
64+
await ctx.respond('You can manage messages.')
65+
"""
66+
67+
invalid = set(perms) - set(Permissions.VALID_FLAGS)
68+
if invalid:
69+
raise TypeError(f"Invalid permission(s): {', '.join(invalid)}")
70+
71+
def inner(command: Callable):
72+
if isinstance(command, ApplicationCommand):
73+
if command.parent is not None:
74+
raise RuntimeError(
75+
"Permission restrictions can only be set on top-level commands"
76+
)
77+
command.default_member_permissions = Permissions(**perms)
78+
else:
79+
command.__default_member_permissions__ = Permissions(**perms)
80+
return command
81+
82+
return inner
83+
84+
85+
def guild_only() -> Callable:
86+
"""A decorator that limits the usage of a slash command to guild contexts.
87+
The command won't be able to be used in private message channels.
88+
89+
Example
90+
-------
91+
92+
.. code-block:: python3
93+
94+
from discord import guild_only
95+
96+
@bot.slash_command()
97+
@guild_only()
98+
async def test(ctx):
99+
await ctx.respond("You're in a guild.")
100+
"""
101+
102+
def inner(command: Callable):
103+
if isinstance(command, ApplicationCommand):
104+
command.guild_only = True
105+
else:
106+
command.__guild_only__ = True
107+
108+
return command
109+
110+
return inner
Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
# This example requires the 'members' privileged intent to use the Member converter.
2-
3-
import discord
4-
5-
intents = discord.Intents.default()
6-
intents.members = True
7-
8-
bot = discord.Bot(debug_guilds=[...], intents=intents)
9-
# Remove debug_guilds and set guild_ids in the slash command decorators
10-
# to restrict specific commands to the supplied guild IDs.
11-
12-
13-
@bot.user_command() # Create a global user command
14-
async def mention(
15-
ctx: discord.ApplicationContext, member: discord.Member
16-
): # User commands give a member param
17-
await ctx.respond(f"{ctx.author.name} just mentioned {member.mention}!")
18-
19-
20-
# User commands and message commands can have spaces in their names
21-
@bot.message_command(name="Show ID") # Creates a global message command
22-
async def show_id(
23-
ctx: discord.ApplicationContext, message: discord.Message
24-
): # Message commands give a message param
25-
await ctx.respond(f"{ctx.author.name}, here's the message id: {message.id}!")
26-
27-
28-
bot.run("TOKEN")
1+
# This example requires the 'members' privileged intent to use the Member converter.
2+
3+
import discord
4+
5+
intents = discord.Intents.default()
6+
intents.members = True
7+
8+
bot = discord.Bot(debug_guilds=[...], intents=intents)
9+
# Remove debug_guilds and set guild_ids in the slash command decorators
10+
# to restrict specific commands to the supplied guild IDs.
11+
12+
13+
@bot.user_command() # Create a global user command
14+
async def mention(
15+
ctx: discord.ApplicationContext, member: discord.Member
16+
): # User commands give a member param
17+
await ctx.respond(f"{ctx.author.name} just mentioned {member.mention}!")
18+
19+
20+
# User commands and message commands can have spaces in their names
21+
@bot.message_command(name="Show ID") # Creates a global message command
22+
async def show_id(
23+
ctx: discord.ApplicationContext, message: discord.Message
24+
): # Message commands give a message param
25+
await ctx.respond(f"{ctx.author.name}, here's the message id: {message.id}!")
26+
27+
28+
bot.run("TOKEN")
Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,46 @@
1-
# This example requires the 'members' privileged intent to use the Member converter.
2-
3-
import discord
4-
5-
intents = discord.Intents.default()
6-
intents.members = True
7-
8-
bot = discord.Bot(intents=intents)
9-
# The debug guilds parameter can be used to restrict slash command registration to only the supplied guild IDs.
10-
# This is done like so: discord.Bot(debug_guilds=[...])
11-
# Without this, all commands are made global unless they have a guild_ids parameter in the command decorator.
12-
13-
# Note: If you want you can use commands.Bot instead of discord.Bot.
14-
# Use discord.Bot if you don't want prefixed message commands.
15-
16-
# With discord.Bot you can use @bot.command as an alias
17-
# of @bot.slash_command but this is overridden by commands.Bot.
18-
19-
20-
@bot.slash_command(guild_ids=[...]) # Create a slash command
21-
async def hello(ctx: discord.ApplicationContext):
22-
"""Say hello to the bot""" # The command description can be supplied as the docstring
23-
await ctx.respond(f"Hello {ctx.author}!")
24-
# Note: interactions must be responded to within 3 seconds, if they're not, an
25-
# "Unknown interaction" error will be raised, you can circumvent this by using "ctx.defer()".
26-
# Additional note: You cannot respond to the same interaction twice!
27-
28-
29-
@bot.slash_command(name="hi")
30-
async def global_command(
31-
ctx: discord.ApplicationContext, num: int
32-
): # Takes one integer parameter
33-
await ctx.respond(f"This is a global command, {num}!")
34-
35-
36-
@bot.slash_command(guild_ids=[...])
37-
async def joined(ctx: discord.ApplicationContext, member: discord.Member = None):
38-
# Setting a default value for the member parameter makes it optional ^
39-
user = member or ctx.author
40-
await ctx.respond(
41-
f"{user.name} joined at {discord.utils.format_dt(user.joined_at)}"
42-
)
43-
44-
45-
# To learn how to add descriptions and choices to options, check slash_options.py
46-
bot.run("TOKEN")
1+
# This example requires the 'members' privileged intent to use the Member converter.
2+
3+
import discord
4+
5+
intents = discord.Intents.default()
6+
intents.members = True
7+
8+
bot = discord.Bot(intents=intents)
9+
# The debug guilds parameter can be used to restrict slash command registration to only the supplied guild IDs.
10+
# This is done like so: discord.Bot(debug_guilds=[...])
11+
# Without this, all commands are made global unless they have a guild_ids parameter in the command decorator.
12+
13+
# Note: If you want you can use commands.Bot instead of discord.Bot.
14+
# Use discord.Bot if you don't want prefixed message commands.
15+
16+
# With discord.Bot you can use @bot.command as an alias
17+
# of @bot.slash_command but this is overridden by commands.Bot.
18+
19+
20+
@bot.slash_command(guild_ids=[...]) # Create a slash command
21+
async def hello(ctx: discord.ApplicationContext):
22+
"""Say hello to the bot""" # The command description can be supplied as the docstring
23+
await ctx.respond(f"Hello {ctx.author}!")
24+
# Note: interactions must be responded to within 3 seconds, if they're not, an
25+
# "Unknown interaction" error will be raised, you can circumvent this by using "ctx.defer()".
26+
# Additional note: You cannot respond to the same interaction twice!
27+
28+
29+
@bot.slash_command(name="hi")
30+
async def global_command(
31+
ctx: discord.ApplicationContext, num: int
32+
): # Takes one integer parameter
33+
await ctx.respond(f"This is a global command, {num}!")
34+
35+
36+
@bot.slash_command(guild_ids=[...])
37+
async def joined(ctx: discord.ApplicationContext, member: discord.Member = None):
38+
# Setting a default value for the member parameter makes it optional ^
39+
user = member or ctx.author
40+
await ctx.respond(
41+
f"{user.name} joined at {discord.utils.format_dt(user.joined_at)}"
42+
)
43+
44+
45+
# To learn how to add descriptions and choices to options, check slash_options.py
46+
bot.run("TOKEN")

0 commit comments

Comments
 (0)