我想创建一个带有默认前缀的命令来重置我的机器人的当前前缀。
@bot.command()
async def prefix(ctx, arg):
bot.command_prefix = arg
await ctx.send("You prefix has been updated to: "+str(arg))
@bot.event()
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith("-reset"):
bot.command_prefix = "-"
await ctx.send("You prefix has been reseted to: -")
当我执行它时,只有 bot.event()
部分有效。我没有收到任何错误,但 bot.command() 代码不起作用
答案 0 :(得分:0)
除非在最后添加 @bot.event
,否则 await bot.process_commands(message)
会阻止其他命令。
这是您更正后的代码。
@bot.command()
async def prefix(ctx, arg):
bot.command_prefix = arg
await ctx.send("Your prefix has been updated to: "+str(arg))
@bot.event
async def on_message(message):
if message.author == bot.user:
return
if message.content.startswith("-reset"):
bot.command_prefix = "-"
await message.channel.send("Your prefix has been reset")
await bot.process_commands(message)