Python Bot发送消息两次

Python Bot发送消息两次,python,discord,discord.py,discord.py-rewrite,Python,Discord,Discord.py,Discord.py Rewrite,我刚刚知道如何在discord.py中检查反应,但现在我有另一个问题。当只有一个反应发生时,bot会为两个反应发送两条消息 @bot.command() @commands.has_any_role("Franchise Owner", "General Manager", "Head Coach") async def offer(ctx, member:discord.Member): embed = di

我刚刚知道如何在discord.py中检查反应,但现在我有另一个问题。当只有一个反应发生时,bot会为两个反应发送两条消息

        
@bot.command()
@commands.has_any_role("Franchise Owner", "General Manager", "Head Coach")
async def offer(ctx, member:discord.Member):
    embed = discord.Embed()
    embed.add_field(name="<a:Loading:768095883664424971> Incoming Offer", value=f"The <:DallasCowboys:788796627161710592> have offered {member.mention}.")

    offer_sent = await ctx.send(embed=embed)

    await offer_sent.add_reaction("<a:CheckMark:768095274949935146>")
    await offer_sent.add_reaction("<a:XMark:768095331555606528>")
    await member.send("You have been offered to the <:DallasCowboys:788796627161710592>. You have 30 minutes to accept/decline.")

    channel = ctx.channel

    def check(reaction, member):
        return member == member and str(reaction.emoji) == '<a:CheckMark:768095274949935146>'

    try:
        reaction, user = await bot.wait_for('reaction_add', timeout=1800.0, check=check)
    except asyncio.TimeoutError:
        await channel.send(f"{member.mention} hasn't reacted in time.")
    else:
         await channel.send(f"{ctx.author.mention}, {member.mention} has accepted <:DallasCowboys:788796627161710592> offer.")
         
    def check(reaction, member):
        return member == member and str(reaction.emoji) == '<a:XMark:768095331555606528>'

    try:
        reaction, user = await bot.wait_for('reaction_add', timeout=1800.0, check=check)
    except asyncio.TimeoutError:
        await channel.send(f"{member.mention} hasn't reacted in time.")
    else:
        await channel.send(f"{ctx.author.mention}, {member.mention} has declined <:DallasCowboys:788796627161710592> offer.")

    await asyncio.sleep(1800)
    await offer_sent.delete()

@bot.command()
@指挥部。担任任何职务(“特许经营权所有人”、“总经理”、“主教练”)
异步def提供(ctx,成员:discord.member):
embed=discord.embed()
embed.add_字段(name=“incomming Offer”,value=f“have Offer{member.notice}”)
发送的报价=等待ctx.send(嵌入=嵌入)
等待报价发送。添加反应(“”)
等待报价发送。添加反应(“”)
等待会员。发送(“您已被提供给。您有30分钟时间接受/拒绝。”)
频道=ctx.channel
def检查(反应,成员):
返回成员==成员和str(reaction.emoji)=''
尝试:
反应,用户=等待机器人。等待('反应添加',超时=1800.0,检查=检查)
除asyncio.TimeoutError外:
wait channel.send(f“{member.antify}未及时响应。”)
其他:
wait channel.send(f“{ctx.author.title},{member.title}已接受报价。”)
def检查(反应,成员):
返回成员==成员和str(reaction.emoji)=''
尝试:
反应,用户=等待机器人。等待('反应添加',超时=1800.0,检查=检查)
除asyncio.TimeoutError外:
wait channel.send(f“{member.antify}未及时响应。”)
其他:
wait channel.send(f“{ctx.author.title},{member.title}已拒绝报价。”)
等待异步睡眠(1800)
等待报价发送。删除()

我最近在我的代码中添加了这个,以检查这两种反应,但无法找出问题所在。

您的代码中没有应该发送两次消息的内容,您可能正在运行两个版本的代码。打开任务管理器并杀死任何不需要的python进程,或者只是重新启动计算机

我很确定您运行了两次该程序,为了确保不会发生这种情况,我建议实现一个kill开关,以便每次重新运行该程序时,首先在Discord上激活kill开关,然后再次运行该程序。我制作的killswitch的一个例子如下:

@client.command()
异步def退出(ctx):
等待ctx.send(“关闭bot”)
return wait client.logout()#这将关闭bot。

我曾经遇到过这个问题,主要原因是:Heroku。
如果你在别的地方托管你的机器人,也许你应该改变它们的前缀,这样你就不会同时触发它们了

我测试了代码,无法重现问题。试试LaughlanMcG所说的,如果这不起作用,请考虑添加更多的细节。检查你是否不止一次地运行代码,你必须关闭其他版本。如果这不是问题所在,可能是因为您正在使用
on_message()
事件。有可能会多次调用
process\u commands()
。哦,好吧,当我进行测试时,我发现只有当两个命令都响应时,它才会同时发送这两个命令。有没有一种方法可以在出现反应时立即结束命令?嗯,我正在repl.it中运行bot。代码有12个不同的文件,因为我正在为每个团队制作带有表情前缀的机器人。我知道我可以把它放在一个整体上,但我有它单独的更多定制。这会影响什么吗?嗯,我在不同的地方托管它,但我确实更改了前缀。它只发送两次需要反应的命令消息。我不确定在检测到第一个反应后,我是否可以使用killswitch,所以请告诉我是否可以@Phan Nhật-Huy