【问题标题】:Why is on_message() not working? discord.py为什么 on_message() 不起作用?不和谐.py
【发布时间】:2022-01-04 22:09:25
【问题描述】:

当我使用此代码时,它通常对我有效,但它停止工作。首先使用其他异步定义,但现在 on_message 不起作用!

async def on_ready():
    print("WizBot is currently online! Go check your Discord server; the bot should be active."

@client.event
async def on_message(message):
    if message.author == client.user:
        return
    if message.content.startswith('+test'):
        await message.channel.send('WizBot is up and running!')

WizBot 是我的机器人的名称。如果它有帮助,我正在使用 repl.it。虽然 on_ready() 有效,但我在 def on_message(message) 中得到了 d 的 pyflakes SyntaxError。 View error message

File "main.py", line 21
    async def on_message(message):
          ^
SyntaxError: invalid syntax

有人可以帮忙吗?

【问题讨论】:

    标签: python function discord discord.py


    【解决方案1】:

    我认为是因为缺少右括号

    print("WizBot is currently online! Go check your Discord server; the bot should be active."
    

    【讨论】:

      【解决方案2】:

      你错过了一行中的括号

      print("WizBot is currently online! Go check your Discord server; the bot should be active."
      

      应该是:

      print("WizBot is currently online! Go check your Discord server; the bot should be active.")
      

      【讨论】:

      • 是的,谢谢。我一定是意外删除了括号。
      猜你喜欢
      • 2021-09-27
      • 2021-10-31
      • 2021-08-05
      • 2018-10-14
      • 2021-08-23
      • 2019-03-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多