我正在尝试制作一个机器人,用于将人列入白名单和不列入白名单。我使用replit是因为它有简单的数据库-代码将在他们的数据库中运行。所以我开始制作机器人白名单,这很容易。当我开始取消hitellisting时,出现了一个错误。。。 当我是V.I.P机器人时,它说我不是。请帮帮我。。。 代码:
@client.command()
async def unwhitelist(ctx, user):
role = ctx.guild.get_role(893143464781422612)
if role in ctx.author.roles:
try:
if len(db[str(user)]) != -1:
del db[str(user)]
await ctx.send(f'Succesfult deleted {str(user)} from V.I.P')
except:
await ctx.send(f'{str(user)} is not V.I.P')
else:
await ctx.send('U dont have Permission')
DB看起来像这样:
{'user', 'user1', 'user2'}
DB是replit的插件,所以。。。别弄糊涂了
TLDR
替换
与
解释
既然你有
变量
db
是一个set
,它是不可下标的。因此,当代码运行db[str(user)]
(作为if
条件的一部分)时,您会得到错误这个错误被捕获在
except
块中,因此您的程序发送消息说您不是VIP相关问题 更多 >
编程相关推荐