gpt4 book ai didi

python - Discord Bot 返回 "HTTPException: BAD REQUEST (status code: 400): Cannot send an empty message"尽管我发送的是非空消息

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:21:38 25 4
gpt4 key购买 nike

所以我是整个 discord 机器人场景的新手,我正在尝试从我正在处理的这个机器人将函数返回值打印到 discord 服务器。

我有这个函数,它只返回传入的字符串:

def returnParameter(string):
return string

当我尝试将此函数作为命令调用到我的 discord 服务器中的机器人时通过键入例如 .bot hello world!,将执行以下代码:

@client.command(aliases = ["bot", "BOT"])
async def botFunction(ctx, *, command):
response = returnParameter(command)
await ctx.send(print(response))

使用上面的示例,我希望我的 discord 服务器打印出 "hello world!"但是我得到了这个错误:

Traceback (most recent call last):
File "/Users/User1/Desktop/Python/venv/lib/python3.7/site-packages/discord/ext/commands/bot.py", line 860, in invoke
await ctx.command.invoke(ctx)
File "/Users/User1/Desktop/Python/venv/lib/python3.7/site-packages/discord/ext/commands/core.py", line 698, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "/Users/User1/Desktop/Python/venv/lib/python3.7/site-packages/discord/ext/commands/core.py", line 72, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: HTTPException: BAD REQUEST (status code: 400): Cannot send an empty message

最佳答案

两个问题:

  1. 您的函数和命令似乎同名。你应该给他们不同的名字。

  2. print(response) 返回 None。你应该只是做 await ctx.send(response)

关于python - Discord Bot 返回 "HTTPException: BAD REQUEST (status code: 400): Cannot send an empty message"尽管我发送的是非空消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56086197/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com