【问题标题】:Discord.py / Error: Ignoring exception in on_messageDiscord.py / 错误:忽略 on_message 中的异常
【发布时间】:2021-05-03 18:01:01
【问题描述】:

您好,我正在使用 Visual Studio/python 并尝试制作一个不和谐的机器人。无论我做什么,我都会遇到这个错误。 Ignoring exception in on_message/Traceback (most recent call last):

该程序在 Visual Studio 中运行我的功能,并伴有错误,但它没有出现在我写消息的不和谐聊天中。

@client.event
async def on_message(message):
   
   if message.author == client.user:
       return
 
   if message.content.startswith('$hello'):
     
     await message.channel.send('write a message:')
     msg = await client.wait_for("message")
     parameter = msg.content
         
     await message.channel.send(defname(parameter)) ```                                                       

EDIT: ookay the problem was in my FUNCTION, which was ending on print(), instead of return ""

【问题讨论】:

  • PLEASE DO NOT POST TEXT AS IMAGES。将文本复制并粘贴到您的问题中,并使用代码格式化工具正确格式化。图像不可搜索,也无法通过屏幕阅读器为有视力障碍的人解读。使用edit 链接修改您的问题。
  • 可以发完整码吗?
  • FIXED 问题出在我的 FUNCTION 中,它以 print() 结束,而不是 return ""

标签: python discord.py


【解决方案1】:

你可能没有实例化 Discord 客户端,只是从 discord.py 中导入了客户端

import discord

client = discord.Client()


@client.event
async def on_message(message):
   
   if message.author == client.user:
       return
 
   if message.content.startswith('$hello'):
     
     await message.channel.send('write a message:')
     msg = await client.wait_for("message")
     parameter = msg.content
         
     await message.channel.send(defname(parameter))
 

 client.run('your token here')

【讨论】:

  • 谢谢,我的问题真的很糟糕。所以问题出在我的 FUNCTION 中,它以 print() 结尾,而不是 return ""。
猜你喜欢
  • 2020-11-03
  • 1970-01-01
  • 2014-06-10
  • 2021-02-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多