discord.py-rewrite将某些人从黑名单中删除 [英] discord.py-rewrite Blacklist certain people from using the bot

查看:64
本文介绍了discord.py-rewrite将某些人从黑名单中删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个类似于"Discord Deliver"的漫游器.和"Discord Byte"人们可以在这里订购虚拟食品,我希望能够将某些人从使用该漫游器的名单中列入黑名单.有什么办法吗?对于我所有的命令,我都使用 @ bot.command ;我将其指定为某些人使用 on_message .抱歉,我没有尝试过任何东西,对discord.py-rewrite来说我还比较陌生.

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.

推荐答案

您可以创建一个包含其名称的集合,如果命令的作者姓名在该集合中,则退出该函数.

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

in 中使用集而不是列表会更好,因为查找时间是O(1)而不是O(n).

Using a set instead of a list for in is better because the lookup time is O(1) instead of O(n).

这篇关于discord.py-rewrite将某些人从黑名单中删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆