【问题标题】:Discord Bot returning "HTTPException: BAD REQUEST (status code: 400): Cannot send an empty message" although I am sending a non-empty messageDiscord Bot 返回“HTTPException: BAD REQUEST (status code: 400): Cannot send an empty message”虽然我发送的是非空消息
【发布时间】:2019-09-28 20:53:33
【问题描述】:

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

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

def returnParameter(string):
    return string

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

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

使用上面的例子,我希望我的不和谐服务器打印出"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

【问题讨论】:

    标签: python http bots discord discord.py


    【解决方案1】:

    两个问题:

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

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

    【讨论】:

    • 哇,它成功了:我的第一个问题是我的错,将信息复制到堆栈上时,但第二个问题我并没有真正考虑过......为什么我们不使用打印,不和谐功能如何如果我们不明确告诉它,知道打印字符串吗?
    • ctx.send 将消息发送到不和谐。如果您还想将字符串打印到控制台或日志,您应该在单独的行上执行此操作。
    猜你喜欢
    • 2020-11-08
    • 2019-08-09
    • 1970-01-01
    • 1970-01-01
    • 2021-10-06
    • 2021-09-16
    • 1970-01-01
    • 1970-01-01
    • 2018-09-21
    相关资源
    最近更新 更多