【问题标题】:Reset Prefix in discord.py在 discord.py 中重置前缀
【发布时间】:2021-05-07 15:49:24
【问题描述】:

我想创建一个带有默认前缀的命令来重置我的机器人的当前前缀。

@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() 代码不起作用

【问题讨论】:

  • 你为什么使用bot.command和in-on_message命令?

标签: python discord.py


【解决方案1】:

@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)

【讨论】:

    猜你喜欢
    • 2021-02-03
    • 2021-04-04
    • 2021-04-04
    • 1970-01-01
    • 2021-03-31
    • 1970-01-01
    • 2019-11-30
    • 2021-02-07
    • 2021-04-08
    相关资源
    最近更新 更多