当我有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)
你必须放置await bot.process_commands(message)
之外的if
声明范围,process_command
无论消息是否以“/lockdown”开头,都应该运行。
@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
装饰器将是:
@bot.event
async def on_message(message):
if message.channel.is_private or discord.utils.get(message.author.roles, name="Admin") is None:
return False
if message.content.startswith('/lockdown'):
...
await bot.process_commands(message)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)