【问题标题】:How do you create aliases with spaces in discord py?如何在 discord py 中创建带空格的别名?
【发布时间】:2020-09-22 19:16:21
【问题描述】:

我一直在使用 discord py,我希望在有人写“No u”时调用一个命令。一个问题是,我不能让它工作,因为它里面有一个空间。我尝试使用转义码,但也没有用。

【问题讨论】:

标签: python discord.py


【解决方案1】:

简短的回答是您不能简单地使用命令装饰器创建带有空格的别名。长答案是你can 有一些额外的代码。

但是,您可以使用 on_message 事件,不建议将其用于命令,但足够了:

@bot.event
async def on_message(message):
    await bot.process_commands(message) # add this if you're also using cmd decorators
    if message.content.lower().startswith("no u") and not message.author.bot:
        await message.channel.send("No! You!")

参考资料:

【讨论】:

  • 我有一个问题:每当我输入“No u”时,我的 discord 机器人都会向我发送垃圾邮件,直到我将其关闭。
  • 你要检查作者不是机器人,否则它会自己触发。我将编辑我的答案以说明这一点^
猜你喜欢
  • 2021-08-12
  • 2014-07-29
  • 1970-01-01
  • 2021-02-04
  • 2020-07-09
  • 2017-11-27
  • 1970-01-01
  • 1970-01-01
  • 2013-09-23
相关资源
最近更新 更多