【发布时间】:2018-07-08 00:34:02
【问题描述】:
所以我有两个机器人事件 用“k”响应消息“k”的一种 一个简单的猜测我的数字在 1-10 之间 问题是它们发生冲突,只有一个有效(下面的那个)IDK 我所缺少的。代码:
@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.author.bot: return
if message.content==('k'):
msg = 'k'.format(message)
await client.send_message(message.channel, msg)
await client.process_commands(message)
@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()
guess = await client.wait_for_message(timeout=10.0, author=message.author, check=guess_check)
answer = random.randint(1, 10)
if guess is None:
fmt = 'Sorry, you took too long. It was {}.'
await client.send_message(message.channel, fmt.format(answer))
return
if int(guess.content) == answer:
await client.send_message(message.channel, 'You are right!')
else:
await client.send_message(message.channel, 'Sorry. It is actually {}.'.format(answer))
await client.process_commands(message)
那么我怎样才能让它们不冲突呢?
【问题讨论】:
标签: python bots discord discord.py