【发布时间】:2019-03-12 09:32:53
【问题描述】:
几天前,我开始对编写不和谐机器人有点兴趣。在这些程序的语法中,我注意到很多我无法找到答案的难以理解的问题。 这就是为什么我要求您帮助理解它们。
所有问题都基于此代码:
import discord
import asyncio
from discord.ext import commands
botToken = '***'
client = commands.Bot(command_prefix = '.')
@client.event
async def on_ready():
print('Bot is ready!')
@client.event
async def on_message(message):
author = message.author
if message.content =='Hello':
await client.send_message(message.channel, 'Welcome again {}!'.format(author))
client.run(botToken)
什么是@client.event?我发现这是一个事件处理程序,但它是如何工作的?为什么需要运行程序?它是否以某种方式连接到 asyncio?
【问题讨论】:
-
您是否听说过装饰器,或者您的问题是否比这更具体?
-
我没有听说过,我应该指出我是一个新手程序员。
-
那么你现在有一个研究起点:)
-
非常感谢,我已经找到了关于这些装饰器的一些东西,现在让我们学习。再次感谢。 :P
标签: python python-3.x python-asyncio discord discord.py