当我的代码中有on_message()
时,它会阻止所有其他@bot.command
命令工作。我试过await bot.process_commands(message)
,但这也不起作用。这是我的代码:
@bot.event
@commands.has_role("Owner")
async def on_message(message):
if message.content.startswith('/lockdown'):
await bot.process_commands(message)
embed = discord.Embed(title=":warning: Do you want to activate Lock Down?", description="Type 'confirm' to activate Lock Down mode", color=0xFFFF00)
embed.add_field(name="\u200b", value="Lock Down mode is still in early development, expect some issues")
channel = message.channel
await bot.send_message(message.channel, embed=embed)
msg = await bot.wait_for_message(author=message.author, content='confirm')
embed = discord.Embed(title=":white_check_mark: Lock Down mode successfully activated", description="To deactivate type '/lockdownstop'", color=0x00ff00)
embed.add_field(name="\u200b", value="Lock Down mode is still in early development, expect some issues")
await bot.send_message(message.channel, embed=embed)
答案 0 :(得分:2)
您必须将scrollView
置于await bot.process_commands(message)
语句范围之外,无论消息是否以“/ lockdown”开头,都应运行if
。
process_command
顺便说一下,@bot.event
async def on_message(message):
if message.content.startswith('/lockdown'):
...
await bot.process_commands(message)
无法应用于@commands.has_role(...)
。虽然没有任何错误(因为已经进行了检查),但on_message
实际上并不像您预期的那样有效。
has_role
装饰器的替代方案是:
@has_role