由于某种原因,发送消息在我的不和谐机器人上无法正常工作,我也找不到任何方法来修复它。
import asyncio
import discord
client = discord.Client()
@client.async_event
async def on_message(message):
author = message.author
if message.content.startswith('!test'):
print('on_message !test')
await test(author, message)
async def test(author, message):
print('in test function')
await client.send_message(message.channel, 'Hi %s, i heard you.' % author)
client.run("key")
on_message !test
in test function
Ignoring exception in on_message
Traceback (most recent call last):
File "C:\Users\indit\AppData\Roaming\Python\Python36\site-packages\discord\client.py", line 223, in _run_event
yield from coro(*args, **kwargs)
File "bot.py", line 15, in on_message
await test(author, message)
File "bot.py", line 21, in test
await client.send_message(message.channel, 'Hi %s, i heard you.' % author)
AttributeError: 'Client' object has no attribute 'send_message'
您可能正在运行discord.py的重写版本,因为
discord.Client
对象没有send_message
方法。要解决你的问题,你可以这样做:
但对于我看到的你所做的,我建议使用commands extension
这使得为bot创建bot和为bot创建命令更加简单,例如,下面的一些代码与您的代码完全相同
相关问题 更多 >
编程相关推荐