很抱歉我的英语但是我需要帮助 我可以让bot在if message.content下接收消息吗?
async def on_message(message):
message_loop = message.content
if message.content == "!run":
await message.delete()
random_difficult = ['{}{}{}{}{}{}'.format(random.choice(character),random.choice(character),random.choice(character),random.choice(character),random.choice(character),random.choice(character)),
'{}{}{}{}{}'.format(random.choice(character),random.choice(character),random.choice(character),random.choice(character),random.choice(character)),
'{}{}{}{}{}{}{}'.format(random.choice(character),random.choice(character),random.choice(character),random.choice(character),random.choice(character),random.choice(character),random.choice(character)),]
choice_difficult = random.choice(random_difficult).lower()
await message.channel.send(choice_difficult)
game_embed= discord.Embed(
colour = discord.Colour.dark_blue())
game_embed.set_image(url='https://fakeimg.pl/350x200/?text={}'.format(choice_difficult))
game_embed.set_author(name='... Arcade Game',icon_url='http://mqt-web.tk/image/RBS-Logo.png')
game_embed.set_footer(text='Power by ....', icon_url='http://icons.iconarchive.com/icons/paomedia/small-n-flat/1024/sign-check-icon.png')
game_embed.add_field(name='TEXT', value='TEXT', inline=True)
game_embed.add_field(name='TIME LIMITE', value='20 Sec', inline=True)
message_bot = await message.channel.send(embed=game_embed)
start = True
count = 0
while start == True:
count = count + 1
await asyncio.sleep(1)
if message.content == choice_difficult:
#some code
print(count)
我不知道要做什么
答案 0 :(得分:0)
您可以为此使用wait_for
。因为它在on_message
事件中不起作用。您应该在这样的命令中使用它:
@client.commnad()
async def run(ctx):
await message.delete()
random_difficult = ['{}{}{}{}{}{}'.format(random.choice(character),random.choice(character),random.choice(character),random.choice(character),random.choice(character),random.choice(character)),
'{}{}{}{}{}'.format(random.choice(character),random.choice(character),random.choice(character),random.choice(character),random.choice(character)),
'{}{}{}{}{}{}{}'.format(random.choice(character),random.choice(character),random.choice(character),random.choice(character),random.choice(character),random.choice(character),random.choice(character)),]
choice_difficult = random.choice(random_difficult).lower()
await message.channel.send(choice_difficult)
game_embed= discord.Embed(
colour = discord.Colour.dark_blue())
game_embed.set_image(url='https://fakeimg.pl/350x200/?text={}'.format(choice_difficult))
game_embed.set_author(name='RobuxshopTH Arcade Game',icon_url='http://mqt-web.tk/image/RBS-Logo.png')
game_embed.set_footer(text='Power by ....', icon_url='http://icons.iconarchive.com/icons/paomedia/small-n-flat/1024/sign-check-icon.png')
game_embed.add_field(name='TEXT', value='TEXT', inline=True)
game_embed.add_field(name='TIME LIMITE', value='20 Sec', inline=True)
message_bot = await message.channel.send(embed=game_embed)
start = True
count = 0
while start == True:
count = count + 1
await asyncio.sleep(1)
await client.wait_for('message', check=choice_difficult, timeout=20)
您可以删除timeout
参数,但如果这样做,并且用户从未像choice_difficult
那样响应,则会带来问题。
编辑
您应将函数放在check
参数中,如下所示:
def check():
return choice_difficult
await client.wait_for('message', check=check, timeout=20)
所以新代码是这样的:
@client.commnad()
async def run(ctx):
await message.delete()
random_difficult = ['{}{}{}{}{}{}'.format(random.choice(character),random.choice(character),random.choice(character),random.choice(character),random.choice(character),random.choice(character)),
'{}{}{}{}{}'.format(random.choice(character),random.choice(character),random.choice(character),random.choice(character),random.choice(character)),
'{}{}{}{}{}{}{}'.format(random.choice(character),random.choice(character),random.choice(character),random.choice(character),random.choice(character),random.choice(character),random.choice(character)),]
choice_difficult = random.choice(random_difficult).lower()
await message.channel.send(choice_difficult)
game_embed= discord.Embed(
colour = discord.Colour.dark_blue())
game_embed.set_image(url='https://fakeimg.pl/350x200/?text={}'.format(choice_difficult))
game_embed.set_author(name='RobuxshopTH Arcade Game',icon_url='http://mqt-web.tk/image/RBS-Logo.png')
game_embed.set_footer(text='Power by ....', icon_url='http://icons.iconarchive.com/icons/paomedia/small-n-flat/1024/sign-check-icon.png')
game_embed.add_field(name='TEXT', value='TEXT', inline=True)
game_embed.add_field(name='TIME LIMITE', value='20 Sec', inline=True)
message_bot = await message.channel.send(embed=game_embed)
def check():
return choice_difficult
start = True
count = 0
while start == True:
count = count + 1
await asyncio.sleep(1)
await client.wait_for('message', check=check, timeout=20)