【问题标题】:Discord.py Listening for a Message after a CommandDiscord.py 在命令后监听消息
【发布时间】:2022-01-17 09:54:04
【问题描述】:

我一直在尝试创建一个机器人命令,该命令在发送命令后侦听消息。这旨在用于创建命令作者的配置文件,以便稍后存储在 JSON 文件中。

@client.command()     #creates player profile
async def create(ctx):
    await ctx.send("You will be asked a series of questions to create your Profile. If you accidentally typed this wait 15 seconds for it to cancel.")
    message = await client.wait_for('message',check=None,timeout=15)
    await ctx.send(message) #used to check what message is holding

虽然上面的代码有效,但它并没有按我的意愿工作。它发回服务器、成员、频道、消息和作者的 id 以及其他信息,而不是保存命令作者的回复。

【问题讨论】:

    标签: python discord.py


    【解决方案1】:

    因此,您需要存储用户的输入数据并将其附加为面试表格:

    它接受用户的输入消息并将它们附加到他们回答的消息中:

    q_list = [
        'Your question 1',
        'Your question 2',
        'Your question 3']
    
    a_list = []
    
    
    @client.command()
    async def create(ctx):
    
            await ctx.send("You will be asked a series of questions to create your Profile. If you accidentally typed this wait 15 seconds for it to cancel.")
    
            a_list = []
            submit_channel = client.get_channel(CHANNEL_ID_FOR_SUBMISSIONS)
            channel = await ctx.author.create_dm()
    
            def check(m):
                    return m.content is not None and m.channel == channel
    
            for question in q_list:
                    await asyncio.sleep(3)
                    await channel.send(question)
                    msg = await client.wait_for('message', check=check)
                    a_list.append(msg.content)
    
            submit_wait = True
            while submit_wait:
                    await channel.send(
                        'You have completed the interview, type ``submit`` to confirm')
                    msg = await client.wait_for('message', check=check)
                    if "submit" in msg.content.lower():
                            submit_wait = False
                            answers = "\n".join(f'{a}. {b}' for a, b in enumerate(a_list, 1))
                            submit_msg = f'''**Submission - Created by {msg.author.mention}** \n{answers}'''
                            await submit_channel.send(submit_msg)
    
    
    

    【讨论】:

      猜你喜欢
      • 2017-09-29
      • 2021-12-01
      • 1970-01-01
      • 2021-09-26
      • 2021-05-11
      • 2020-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多