【问题标题】:How can my Discord bot handle multiple inputs?我的 Discord 机器人如何处理多个输入?
【发布时间】:2021-03-25 06:47:32
【问题描述】:

我想在文本频道收到用户的多条消息后调用一个函数,但我不知道该怎么做。

startGame = False
async def on_message(message): # when a new message is detected in the server
    if message.author == client.user: ## don't respond to own message sent by the bot
        return

    if not startGame:
        if message.content == "?startGame": ## start asking for several inputs once user wants to start the game
             await message.channel.send("age?") ## i want to ask for the user's age
             ## ask several other things and store them etc
             startGame = True

但是,我现在不知道如何存储用户的年龄,因为机器人会发送“年龄?”在服务器中然后on_message 将被再次调用但在这种情况下不会做任何事情,所以我不能使用用户的输入

【问题讨论】:

  • 你可能应该定义一个可以存储值的类 User()...

标签: python bots discord.py


【解决方案1】:

为了存储他们输入的年龄值,您可以将.send() 设置为一个变量,如下所示:

msg = await self.bot.wait_for('message')

当用户输入他们的年龄时,它现在被存储到msg 变量中以供其他地方使用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-04-07
    • 2021-04-14
    • 2018-12-17
    • 2018-09-07
    • 2021-02-24
    • 2023-01-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多