Reputation: 1
I want to make a command that I only want to run in servers i want to choose, so is it possible to make a custom check that does this?
Upvotes: 0
Views: 63
Reputation: 3426
You could use checks
which is fairly simple when the return is True the command will procced
This will allow you to use the same check for different commands
Return
True
to signal that the person can run the command.Return
False
to signal that the person cannot run the command.Raise a
CommandError
derived exception to signal the person cannot run the command. This allows you to have custom error messages for you to handle in the error handlers.
async def is_channel(ctx):
return ctx.channel.id in [123,456]
@bot.command()
@commands.check(is_channel)
async def something(ctx):
await ctx.send('Hey.')
Upvotes: 1
Reputation: 1415
You have to options:
allowedGuilds = [some, ids, here]
# 1. Check guild id with an if statement:
@bot.command()
async def test(ctx):
if not ctx.guild.id in allowedGuilds:
return
# your code
# 2. Create your own decorator:
def allowed_guild():
def predicate(ctx):
return ctx.guild.id in allowedGuilds
return commands.check(predicate)
@bot.command()
@allowed_guild()
async def test(ctx):
# your code
Upvotes: 1
Reputation: 157
A simple if statment would work.
@bot.command()
async def yourcommand(ctx):
guilds = [Yourguilidhere, Yourguilidhere, Yourguilidhere]
if ctx.guild.id in guilds:
#do the command here
else:
await ctx.send("You can't use this command here!")
Upvotes: 0