Discord.py 在命令后监听消息

标签 discord.py

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

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
虽然上面的代码可以工作,但它不像我想要的那样工作,它会发回服务器、成员、 channel 、消息和作者的 ID 以及其他信息。而不是持有命令作者的回复。

最佳答案

那么您希望它存储用户的输入数据并将它们附加为面试表格:
它接受用户的输入消息并将它们附加到他们回答的消息中,例如:

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)


关于Discord.py 在命令后监听消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65728788/

相关文章:

python - 参数错误: ValueError: 'params' arg (<class 'list' >) can be only a tuple or a dictionary

python - Discord Python - 私有(private) channel (DM) 中的 bot.wait_for_message

python - Discord.py - 如何从 Bot Command 中提及 Discord 用户

python - MongoDB Atlas 连接在 Heroku 上不起作用

python - discord.py [mp3 @ 000001dc99bec540] 从比特率估计持续时间,这可能不准确

python - 如何获取最长的用户名? (不和谐.py)

python - 无法在 Linux 上的 Python 3.6 中安装 discord.py

python - 等待一个有 for 循环语法错误的函数

python - 如果用户在 channel 中发送命令,则等待 DM 中的消息问题

python - "FFmpeg was not found, spotdl can' t continue”,即使它是使用 sudo apt-get install spotdl 安装的 + 如果从终端运行它也可以工作