You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

我的Discord机器人出现50006错误:无法发送空消息,求排查原因

Discord机器人错误(50006:无法发送空消息)解决

错误原因

你的handle_response函数仅在用户消息完全匹配tell me something bana(转为小写后)时才返回内容,其他所有场景该函数无返回语句,会默认返回None。而Discord API不允许发送空消息(None会被识别为空内容),因此触发错误代码50006的400 Bad Request错误。

另外需注意:如果bana_phrases是空列表,random.choice(bana_phrases)会抛出异常,同样会导致无法生成有效回复。

修复方案

  1. 给handle_response函数添加默认返回值,确保任何输入都能返回非空字符串:
import random

# 先确保bana_phrases有内容,示例:
bana_phrases = ["今天天气不错!", "我是你的专属机器人~", "随便聊点什么吧!"]

def handle_response(message) -> str:
    p__message = message.lower()
    if p__message == 'tell me something bana':
        return random.choice(bana_phrases)
    # 添加默认回复,避免返回None
    return "我没听懂你的意思,换个说法试试?"
  1. 检查bana_phrases列表,确保其中至少包含一个字符串元素,防止random.choice报错。

内容的提问来源于stack exchange,提问作者imnachox2

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.08 09:05:16