【发布时间】:2018-12-16 12:02:56
【问题描述】:
我已经浏览了一些关于如何制作 Discord Python Bot 的示例,并且我看到 client 和 bot 几乎可以互换使用,我无法找到您何时使用哪个什么时候。
例如:
client = discord.Client()
@client.event
async def on_message(message):
# we do not want the bot to reply to itself
if message.author == client.user:
return
if message.content.startswith('$guess'):
await client.send_message(message.channel, 'Guess a number between 1 to 10')
def guess_check(m):
return m.content.isdigit()
@client.event
async def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------')
client.run('token')
对比
bot = commands.Bot(command_prefix='?', description=description)
@bot.event
async def on_ready():
print('Logged in as')
print(bot.user.name)
print(bot.user.id)
print('------')
@bot.command()
async def add(left : int, right : int):
"""Adds two numbers together."""
await bot.say(left + right)
bot.run('token')
我开始认为它们具有非常相似的品质并且可以做同样的事情,但个人偏好是与客户端一起使用而不是与机器人一起使用。但是,它们确实存在差异,客户端拥有on_message,而机器人等待prefix command。
有人可以澄清client 和bot 之间的区别吗?
【问题讨论】:
标签: python discord discord.py