forked from Pycord-Development/pycord
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Pycord-Development#280 from TheGamerX20/slash_perms
Add Slash Command Permissions support.
- Loading branch information
Showing
4 changed files
with
283 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import discord | ||
|
||
# Imports Commands from discord.commands (for Slash Permissions) | ||
from discord.commands import commands | ||
|
||
bot = discord.Bot() | ||
|
||
# Note: If you want you can use commands.Bot instead of discord.Bot | ||
# Use discord.Bot if you don't want prefixed message commands | ||
|
||
# With discord.Bot you can use @bot.command as an alias | ||
# of @bot.slash_command but this is overridden by commands.Bot | ||
|
||
# by default, default_permission is set to True, you can use | ||
# default_permission=False to disable the command for everyone. | ||
# You can add up to 10 permissions per Command for a guild. | ||
# You can either use the following decorators: | ||
# -------------------------------------------- | ||
# @commands.permission(role_id/user_id, permission) | ||
# @commands.has_role("ROLE_NAME") <-- can use either a name or id | ||
# @commands.has_any_role("ROLE_NAME", "ROLE_NAME_2") <-- can use either a name or id | ||
# @commands.is_user(USER_ID) <-- id only | ||
# @commands.is_owner() | ||
# Note: you can supply "guild_id" to limit it to 1 guild. | ||
# Ex: @commands.has_role("Admin", guild_id=GUILD_ID) | ||
# -------------------------------------------- | ||
# or supply permissions directly in @bot.slash_command | ||
# @bot.slash_command(default_permission=False, | ||
# permissions=[commands.Permission(id=ID, type=TYPE, permission=True, guild_id=GUILD_ID)]) | ||
|
||
# Note: Please replace token, GUILD_ID, USER_ID and ROLE_NAME. | ||
|
||
# Guild Slash Command Example with User Permissions | ||
@bot.slash_command(guild_ids=[GUILD_ID], default_permission=False) | ||
@commands.is_user(USER_ID) | ||
async def user(ctx): | ||
"""Say hello to the author""" # the command description can be supplied as the docstring | ||
await ctx.respond(f"Hello {ctx.author}!") | ||
|
||
# Guild Slash Command Example with Owner Permissions | ||
@bot.slash_command(guild_ids=[GUILD_ID], default_permission=False) | ||
@commands.is_owner() | ||
async def owner(ctx): | ||
"""Say hello to the author""" # the command description can be supplied as the docstring | ||
await ctx.respond(f"Hello {ctx.author}!") | ||
|
||
# Guild Slash Command Example with Role Permissions | ||
@bot.slash_command(guild_ids=[GUILD_ID], default_permission=False) | ||
@commands.has_role("ROLE_NAME") | ||
async def role(ctx): | ||
"""Say hello to the author""" # the command description can be supplied as the docstring | ||
await ctx.respond(f"Hello {ctx.author}!") | ||
|
||
# Guild Slash Command Example with Any Specified Role Permissions | ||
@bot.slash_command(guild_ids=[GUILD_ID], default_permission=False) | ||
@commands.has_any_role("ROLE_NAME", "ROLE_NAME2") | ||
async def multirole(ctx): | ||
"""Say hello to the author""" # the command description can be supplied as the docstring | ||
await ctx.respond(f"Hello {ctx.author}!") | ||
|
||
# Guild Slash Command Example with Permission Decorator | ||
@bot.slash_command(guild_ids=[GUILD_ID], default_permission=False) | ||
@commands.permission(user_id=USER_ID, permission=True) | ||
async def permission_decorator(ctx): | ||
"""Say hello to the author""" # the command description can be supplied as the docstring | ||
await ctx.respond(f"Hello {ctx.author}!") | ||
|
||
# Guild Slash Command Example with Permissions Kwarg | ||
@bot.slash_command(guild_ids=[GUILD_ID], default_permission=False, permissions=[commands.Permission(id=USER_ID, type=2, permission=True)]) | ||
async def permission_kwarg(ctx): | ||
"""Say hello to the author""" # the command description can be supplied as the docstring | ||
await ctx.respond(f"Hello {ctx.author}!") | ||
|
||
# To learn how to add descriptions, choices to options check slash_options.py | ||
bot.run("token") |