我一直在学习如何制作Discord Python机器人的例子,我看到 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
,而机器人则等待前缀命令
。
请问有人能澄清一下client
和bot
之间的区别吗?