gpt4 book ai didi

python - 使用Python打印400空消息代码中的变量输出

转载 作者:行者123 更新时间:2023-12-01 01:08:48 33 4
gpt4 key购买 nike

问题:

我正在尝试为 Discord 编写一个机器人,以便获取一个变量并将其作为消息发送。例如,“a”设置为 42,我希望机器人在聊天中打印“The number is 42 {author name}”:

a = 32

if message.content.startswith('!gap'):
msg = print('a'.format(message))
await client.send_message(message.channel, msg)

错误:

Ignoring exception in on_message
Traceback (most recent call last):
File "C:\Users\trevo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\discord\client.py", line 307, in _run_event
yield from getattr(self, event)(*args, **kwargs)
File "C:\Users\trevo\Desktop\dcbot\reply.py", line 16, in on_message
await client.send_message(message.channel, msg)
File "C:\Users\trevo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\discord\client.py", line 1152, in send_message
data = yield from self.http.send_message(channel_id, content, guild_id=guild_id, tts=tts, embed=embed)
File "C:\Users\trevo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\discord\http.py", line 200, in request
raise HTTPException(r, data)
discord.errors.HTTPException: BAD REQUEST (status code: 400): Cannot send an empty message

我很欣赏解释!

最佳答案

您希望 msg 是一个字符串,但如果您尝试一下:

>>> msg = print("anything at all")
>>> repr(msg)
None

只需删除 print 调用即可。

关于python - 使用Python打印400空消息代码中的变量输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55070583/

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