【问题标题】:I cannot understand how to use this code in discord.py我无法理解如何在 discord.py 中使用此代码
【发布时间】:2021-07-27 03:57:38
【问题描述】:

它考虑到用户输入,所以就像我被委托做一个提示但我从来没有这样做过,所以这是我在网上找到的

playerChoice = await bot.wait_for('message', check=check(ctx.author), timeout=30)

我得到了一些,但我没有得到“消息”部分和“检查 = 检查”。

这是我的完整代码


@client.command()
async def event(ctx):
    await ctx.send("Prompt will continue in DMs.")
    embed = discord.Embed(title="Event Prompt", description="Please specify the type of event.")
    embed.set_footer("Prompt will expire in ## seconds")
    await ctx.author.send(embed=embed)
    eventType = await bot.wait_for('message', check=check(ctx.author), timeout=30) # I want it to send the event type.
    await ctx.send(eventType)

我想要一个解释和一种可能的方法来改进它并使其发挥作用。提前致谢

【问题讨论】:

    标签: discord discord.py


    【解决方案1】:

    https://discordpy.readthedocs.io/en/stable/api.html?highlight=wait_for#discord.Client.wait_for

    @client.event
    async def on_message(message):
        if message.content.startswith('$greet'):
            channel = message.channel
            await channel.send('Say hello!')
    
            def check(m):
                return m.content == 'hello' and m.channel == channel
    
            msg = await client.wait_for('message', check=check)
            await channel.send('Hello {.author}!'.format(msg))
    
    await client.wait_for('message', check=check)
    

    message 指事件。您也可以为reaction_addvoice_state_update 等活动这样做。
    所以这意味着您正在等待消息。 check 准确定义了您正在等待的内容。它是一个方法,返回一个TrueFalse

    就我而言,我正在等待 message 事件,该事件发布在同一 channel 中,并且消息内容为 "hello"

    如果你没有这样的检查,它会选择一个message,它可能是由不同的作者、不同的频道、不同的公会发送的。

    【讨论】:

    • 如果我想在命令中转换它,我该怎么做?我可以用 ctx 替换 message 吗?
    猜你喜欢
    • 2017-11-13
    • 1970-01-01
    • 1970-01-01
    • 2019-07-27
    • 1970-01-01
    • 2011-08-28
    • 1970-01-01
    • 2021-07-10
    相关资源
    最近更新 更多