discord.py-rewrite Blacklist certain people from using the bot

好久不见. 提交于 2021-02-11 05:10:29

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!