【发布时间】:2021-01-31 19:59:03
【问题描述】:
我正在尝试为不和谐制作一个投票机器人,以使该人静音。但是,当我运行 Yes 和 No 函数时,出现 Command not found 错误。到目前为止,这就是我所拥有的:
@bot.command(name='votekick')
@commands.has_role('Player')
async def votekick(ctx, user: discord.Member):
await ctx.send('A votekick against {} has started. Type .yes to vote to mute this person and .no if you don\'t want this person to be muted.'.format(user.name))
server = ctx.message.guild
role_id = 805035493573394452
for member in server.members:
if role_id in member.roles:
member.add_roles(get(member.guild.roles, name='able'))
arole = get(member.guild.roles, name='able')
yes=0
no=0
while len(arole.members) > 0:
@bot.command(name='yes')
@commands.has_role('able')
async def voteyes(ctx):
author=ctx.message.author
message=ctx.message
await bot.delete_message(message)
await ctx.send('Player {} has voted.'.format(author.display_name))
author.remove_roles(get(author.guild.roles, name='able'))
global yes
yes=yes+1
@bot.command(name='no')
@commands.has_role('able')
async def voteno(ctx):
author = ctx.message.author
message = ctx.message
await bot.delete_message(message)
await ctx.send('Player {} has voted.'.format(author.display_name))
author.remove_roles(get(author.guild.roles, name='able'))
global no
no = no+1
if yes > no:
return None
else:
await user.edit(mute=True)
谁能告诉我有什么问题?提前致谢!
【问题讨论】:
-
这是一个合理的假设,您可以将一个命令放在另一个命令中,以便一个接一个地发生,但不幸的是,它并不能完全按照这种方式工作。相反,您需要跟踪谁被提名被踢到一个“超过”votekick 函数调用的变量中,这样
voteno或voteyes(不会嵌套)就会知道谁去踢。不幸的是,这确实有点复杂,特别是如果多个人被提名同时被踢。
标签: python-3.x discord.py