简体   繁体   English

你如何让一个不和谐的机器人响应来回?

[英]How do you make a discord bot respond to a back-and-forth?

How do you make a bot respond to a message and ask a question, like你如何让机器人回复消息并提出问题,比如

Me:!guess 10我:!猜10

bot: pick a number between 1 and 10 bot:在 1 到 10 之间选择一个数字

me: 4我:4

bot: incorrect, it was 5!机器人:不正确,是 5!

I can't figure out how to do this, because once you respond to a command, I don't know how to have something like a global variable to save the answer.我无法弄清楚如何做到这一点,因为一旦您响应命令,我不知道如何使用全局变量之类的东西来保存答案。

This is some code I used, hopefully this will help, this give you 5 guesses to get it right and it gives you hints with bigger and expands on what you wanted, so you could adapt it if you don't want the bigger and smaller!这是我使用的一些代码,希望这会有所帮助,这会给您 5 次猜测以使其正确!

@commands.command()
async def game(self, ctx):
    number = random.randint(0, 100)
    for i in range(0, 5):
        await ctx.send('guess')
        response = await self.bot.wait_for('message')
        guess = int(response.content)
        if guess > number:
            await ctx.send('bigger')
        elif guess < number:
            await ctx.send('smaller')
        else:
            await ctx.send('yes!')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM