问题
I am making a bot similar to "Discord Deliver" and "Discord Byte" where people can order virtual food, and I want to be able to black list certain people from using the bot. Is there any way of doing this? For all my commands i use @bot.command
; I am specifying this as some people use on_message
. Sorry that I don't have anything I've tried, I am relatively new to discord.py-rewrite.
回答1:
You can make a set containing their names and exit the function if the command's author's name is in that set.
blacklist = {'name1', 'name2', 'name3'}
@bot.command()
async def command(ctx):
if ctx.author.name in blacklist:
return
# do rest of command
Using a set instead of a list for in
is better because the lookup time is O(1) instead of O(n).
来源:https://stackoverflow.com/questions/62748231/discord-py-rewrite-blacklist-certain-people-from-using-the-bot