本文介绍了discord.py bot机器人重写AttributeError:'Bot'对象没有属性'send_message'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我为不和谐创造了一个机器人,当我在本地启动它时,它可以正常工作。
我在heroku上构建它,似乎也可以正常工作(感谢Tristo)。
但在日志中我收到以下消息:

I made a bot for discord and it works fine when I launch it in local.I build it on heroku and It's seems to work fine too (thanks to Tristo).But in the log I get the following message :

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 +

My requirements.txt includes only "git+https://github.com/Rapptz/discord.py@rewrite#egg=discord.py[voice]"

我尝试使用发送而不是 send_message(答案为

I tried to use "send" instead of "send_message" (the answer in a similar post) but nothing changes.

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

My bot seems to work despite the attribute message error.Could you help me to understand what happened, please ?

推荐答案

您已安装了<$的重写分支。 c $ c> discord.py 执行

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

# after
await channel.send('Hello')

这篇关于discord.py bot机器人重写AttributeError:'Bot'对象没有属性'send_message'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 23:14