python 为什么我的discord机器人给予以下错误?

iqih9akk  于 2022-12-17  发布在  Python
关注(0)|答案(1)|浏览(160)

我不明白为什么它会给出这个错误!它吃了我的头

@client.event
    async def on_message(message):
        # Make sure bot doesn't get stuck in an infinite loop
        if message.author == client.user:
            return

        # Get data about the user
        username = str(message.author)
        user_message = str(message.content)
        channel = str(message.channel)

        # Debug printing
        print(f"{username} dice: '{user_message}' ({channel})")

        # If the user message contains a '?' in front of the text, it becomes a private message
        if user_message[0] == '?':
            user_message = user_message[1:]  # [1:] Removes the '?'
            await send_message(message, user_message, is_private=True)
        else:
            await send_message(message, user_message, is_private=False)

它在那里做的唯一事情就是调用一个名为“send_message”的模块
x一个一个一个一个x一个一个二个x
400错误请求(错误代码:50006):无法发送空消息

elcex8rz

elcex8rz1#

您应该使用检查来确保handle_response函数返回字符串(如果消息不是tell me something bana,则不会返回字符串):

async def send_message(message, user_message, is_private):
     try:
         response = responses.handle_response(user_message)
         if response:
              await message.author.send(response) if is_private else await message.channel.send(response)
     except Exception as e:
         print(e)

相关问题