【问题标题】:How do I stop my bot from spamming discord.py如何阻止我的机器人向 discord.py 发送垃圾邮件
【发布时间】:2021-03-05 23:42:09
【问题描述】:

我正在执行设置命令。一切正常,但命令垃圾邮件而不是发送一次

@kara.command()
async def setup(ctx):
        guild = ctx.guild
        await ctx.message.delete()
        await guild.create_role(name=silenced, permissions = discord.Permissions(send_messages=False), reason=f"Invoked by {ctx.author}")
        role = discord.utils.get(guild.roles, name = "Silenced")
        for chan in guild.channels:
            await chan.set_permissions(silenced, send_messages=False)
            setup=discord.Embed(title="Kara's setup", color=c.teal(), url=rick_roll, description="If the setup goes wrong make sure I have the correct permissions!")
            setup.add_field(name="Silenced Role", value="Setting up my own muted role...")
            msg = await ctx.send(embed=setup)
            
            setup2=discord.Embed(title="Kara's setup", color=c.teal(), url=rick_roll, description="If the setup goes wrong make sure I have the correct permissions!")
            setup2.add_field(name="Silenced Role", value="Setting up my own muted role...")
            setup2.add_field(name="Coming Soon...", value="Currently this is all to the setup soo... yea")
            msg = await ctx.send(embed=setup)
            await asyncio.sleep(3.4)
            await msg.edit(embed=setup2)

它只是将我尝试将发送移到 for 之外的设置发送垃圾邮件,但没有任何帮助。

【问题讨论】:

  • 检查是否有更多的实例在运行。如果是这样,请关闭它们。也是齿轮内的代码吗?提供详细信息
  • 这是垃圾邮件,因为您在 for 循环中添加了 await ctx.send(embed=setup)。这就是你想要的
  • 如何删除并发送一次
  • 它在一个齿轮之外

标签: python python-3.x discord discord.py


【解决方案1】:

您应该在await msg.edit(embed=setup2) 下添加break

编辑:另一个原因可能是您的on_message 事件错过了await bot.process_commands(message)。请注意,这应该与async def on_message(msg): 的缩进匹配。只需确保在活动结束时添加它即可。

【讨论】:

  • 如果他们尝试过,那个循环只会运行一次,对吧?这肯定会阻止垃圾邮件,但似乎也摆脱了该代码的意图。
  • 不是命令吗?命令完成后,循环可以被打破。假设您想在命令中查找guild.name,则可以使用break。因为如果我们再次执行这个命令,我们就可以开始这个循环。并感谢您对我的回答进行编辑。这是一个有用的编辑。
  • 我不知道您是对还是错,但如果您添加该解释,它可能会帮助您回答。此外,我在他们正在寻找 guild.name 的问题中提供的代码中也没有看到,也许这确实是问题所在。您的澄清编辑将不胜感激。
猜你喜欢
  • 1970-01-01
  • 2014-08-12
  • 2011-10-31
  • 2014-09-27
  • 1970-01-01
  • 2012-06-12
  • 1970-01-01
  • 1970-01-01
  • 2014-10-22
相关资源
最近更新 更多