gpt4 book ai didi

python - discord.py 机器人重写 AttributeError : 'Bot' object has no attribute 'send_message'

转载 作者:太空宇宙 更新时间:2023-11-03 21:23:54 25 4
gpt4 key购买 nike

我为discord制作了一个机器人,当我在本地启动它时它运行良好。我在 Heroku 上构建它,它似乎也工作得很好(感谢 Tristo)。但在日志中我收到以下消息:

2019-01-01T23:06:50.131982+00:00 app[worker.1]: Ignoring exception in on_message
2019-01-01T23:06:50.132550+00:00 app[worker.1]: Traceback (most recent call last):
2019-01-01T23:06:50.132589+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/discord/client.py", line 227, in _run_event
2019-01-01T23:06:50.132590+00:00 app[worker.1]: await coro(*args, **kwargs)
2019-01-01T23:06:50.132593+00:00 app[worker.1]: File "run.py", line 14, in on_message
2019-01-01T23:06:50.132594+00:00 app[worker.1]: await client.send_message(message.channel, newMessage)
2019-01-01T23:06:50.132616+00:00 app[worker.1]: AttributeError: 'Bot' object has no attribute 'send_message'

我的程序是:

from discord.ext.commands import Bot
import os

BOT_PREFIX = ("?")
access_token= os.environ["ACCESS_TOKEN"]

client = Bot(command_prefix=BOT_PREFIX)

@client.event
async def on_message(message):
if message.content.startswith("?"):
newMessage = 'text' + str(message.content)[1:].upper() + '.png'
await client.send_message(message.channel, newMessage)

client.run(access_token)

我的requirements.txt仅包含“git+ https://github.com/Rapptz/discord.py@rewrite#egg=discord.py[voice]

我尝试使用“send”而不是“send_message”(类似帖子中的答案),但没有任何变化。

尽管出现属性消息错误,我的机器人似乎仍能正常工作。您能帮我了解发生了什么吗?

最佳答案

您已经安装了 discord.py 的重写分支,该分支执行 sending messages以不同的方式

# before
await client.send_message(channel, 'Hello')

# after
await channel.send('Hello')

关于python - discord.py 机器人重写 AttributeError : 'Bot' object has no attribute 'send_message' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53999771/

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