出于某种原因,send_message 在我的 Discord 机器人上无法正常工作,而且我无法找到修复它的方法。
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'
原文由 cute 发布,翻译遵循 CC BY-SA 4.0 许可协议
您可能正在运行 discord.py 的重写版本,因为
discord.Client
对象没有send_message
方法。要解决您的问题,您可以将其作为:
但是对于我看到你所做的,我建议使用 命令扩展
这使得为机器人创建机器人和命令变得更加简单,例如,这里有一些代码与您的代码完全相同