我正在提出一个建议。它第一次运行得非常好,之后,它会自动选择一个表情符号并将其发回

2024-10-02 00:43:55 发布

您现在位置:Python中文网/ 问答频道 /正文

@bot.command()
async def suggest(ctx,*,suggestion):
    # await ctx.channel.purge(limit = 1)
    
    emojis = ['✅','❌']
    
    channel = bot.get_channel(xxxxxxxxxxxx)
    await ctx.send('Your Suggestion has been sent, will be reviewed by admin shortly')
    suggestEmbed = discord.Embed(colour=0x28da5b)
    suggestEmbed=discord.Embed(title="Suggestion Bot", description="Please mark ✅ or ❌ depending on whether you want to take this suggestion or not", color=0x28da5b)
    
    message = await channel.send(embed = suggestEmbed)
    await message.add_reaction('✅')
    await message.add_reaction('❌')
    
    sendEmbed = discord.Embed(colour = 0x28da5b)
    sendEmbed.add_field(name = 'New Suggestion!', value  = f'{suggestion}')

    
    try:
        reaction, user = await bot.wait_for('reaction_add')
        while reaction.message == message:
            if str(reaction.emoji) == "✅":
                await ctx.send("🚀🚀🚀 Yay! Your suggestion has been approved, We thank you for your valuable time!")
                await ctx.send("Your Suggestion was: ")
                message1 = await ctx.send(embed = sendEmbed)
                await channel.send("The above suggestion has been approved, this post will no longer be active")
                return
            if str(reaction.emoji) == "❌":
                await ctx.send("🙇‍♀️🙇‍♀️ Sorry! Your suggestion has not been approved, We thank you for your valuable time!")
                await ctx.send("Your Suggestion was: ")
                message1 = await ctx.send(embed = sendEmbed)
                await channel.send("The above suggestion has not been approved, this post will no longer be active")
                return
    except Exception:
        return

我希望我的代码能提供一些建议,它会转到另一个频道,在那里管理员可以点击勾号或错误的按钮。当勾选点击时,它应该发送已经接受的建议。它第一次运行很好,但当我第二次运行它时,它不需要交互,它会自动点击2个表情符号中的随机表情符号并将其发回


Tags: sendaddmessageyourbotchannelawaithas
1条回答
网友
1楼 · 发布于 2024-10-02 00:43:55

因为您还没有定义check,所以它还接受bot的反应输入。定义了一个检查函数

def check (reaction, user): 
         return not user.bot and message == reaction.message #checks if the reacting user isn't a bot (inside the command)

#use this with check kwarg inside wait_for

reaction, user = await bot.wait_for('reaction_add', check=check)

最终代码:

bot.remove_command("suggest")
@bot.command()
async def suggest(ctx,*,suggestion):
    # await ctx.channel.purge(limit = 1)
    
    emojis = ['✅','❌']
    
    channel = ctx.channel
    await ctx.send('Your Suggestion has been sent, will be reviewed by admin shortly')
    suggestEmbed = discord.Embed(colour=0x28da5b)
    suggestEmbed=discord.Embed(title="Suggestion Bot", description="Please mark ✅ or ❌ depending on whether you want to take this suggestion or not", color=0x28da5b)
    
    message = await channel.send(embed = suggestEmbed)
    await message.add_reaction('✅')
    await message.add_reaction('❌')
    
    sendEmbed = discord.Embed(colour = 0x28da5b)
    sendEmbed.add_field(name = 'New Suggestion!', value  = f'{suggestion}')

    def check (reaction, user):
         return not user.bot and message == reaction.message
    try:
        reaction, user = await bot.wait_for('reaction_add', check=check)
        while reaction.message == message:
            if str(reaction.emoji) == "✅":
                await ctx.send("🚀🚀🚀 Yay! Your suggestion has been approved, We thank you for your valuable time!")
                await ctx.send("Your Suggestion was: ")
                message1 = await ctx.send(embed = sendEmbed)
                await channel.send("The above suggestion has been approved, this post will no longer be active")
                return
            if str(reaction.emoji) == "❌":
                await ctx.send("🙇‍♀️🙇‍♀️ Sorry! Your suggestion has not been approved, We thank you for your valuable time!")
                await ctx.send("Your Suggestion was: ")
                message1 = await ctx.send(embed = sendEmbed)
                await channel.send("The above suggestion has not been approved, this post will no longer be active")
                return
    except Exception:
        return

相关问题 更多 >

    热门问题