【发布时间】:2018-06-15 11:00:55
【问题描述】:
由于某种原因,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'
【问题讨论】:
-
你是在异步还是重写分支?
-
在纠正错误的缩进并使用我自己的令牌后,它在我的 Linux 机器上运行良好。
标签: python python-3.x discord discord.py