【发布时间】:2019-07-23 21:06:52
【问题描述】:
我刚刚开始使用不和谐的机器人,也没有很长时间使用 python。我正在制作一个货币机器人,货币为 ep,它跟踪用户的财富并将所有内容保存在 json 文件中。我之前也做过这个工作,但想用不同的方式来写它。
我最初的方式-
@client.event
async def on_message(message):
if message.content.upper().startswith('EP.PING'):
await client.send_message(message.channel, "Ping.")
我的(希望是更好的方式)-
@client.command()
async def ping():
await client.say('Pong')
错误信息 -
File "f:/Python Programs/EP Bot/EP Bot V2.py", line 19, in <module>
@client.command()
File "F:\Python 3.6.4\lib\site-packages\discord\client.py", line 296, in __getattr__
raise AttributeError(msg.format(self.__class__, name))
AttributeError: '<class 'discord.client.Client'>' object has no attribute 'command'
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x000001E73CDBBDA0>
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x000001E73CDCE0B8>
非常感谢您提供帮助,如果您认为我的初始方法更好,那也没关系,我只是认为如果可行,这会容易得多。
如果您知道任何参考代码或模板,那就太好了!
【问题讨论】:
-
我不是 discord.py 或装饰器方面的专家,但为了保持一致性,
@client.command()不应该是@client.command吗? -
@RandomDavis No.
client.command()是一个返回装饰器的函数。
标签: python python-3.x discord discord.py