Reputation: 23
I'm trying to make this command where only the owner can run it. Is there anyway to check for the highest role or the creator of the server?
I tried '@commands.is_owner()' but that only checks if someone is the owner of the bot.
Upvotes: 2
Views: 3997
Reputation: 27
You can use the decorator:
@commands.has_role("RoleName")
Example:
import discord
from discord.ext import commands
from discord.ext.commands.core import command
@bot.command
@commands.has_role("RoleName")
async def ...(ctx)
await ctx.send("your message")
Let me know if it works!
Edit: you can also import everything:
import discord
from discord import user
from discord.ext import commands
from discord.ext.commands.core import command
from discord.member import Member
from discord.message import Message
from discord.user import User
Upvotes: 1
Reputation: 421
Guild.owner
exists, so here's an example of its use!
from discord.ext import commands
bot = commands.Bot(command_prefix="your_prefix")
# example use with custom decorator
def guild_owner_only():
async def predicate(ctx):
return ctx.author == ctx.guild.owner # checks if author is the owner
return commands.check(predicate)
@bot.command()
@guild_owner_only()
async def ...
Upvotes: 3