【问题标题】:Cogs command message sending twiceCogs 命令消息发送两次
【发布时间】:2020-07-25 03:41:49
【问题描述】:

我昨天切换到 cogs,所以我的代码看起来更干净。从那时起,所有命令都被破坏了。如果您发送 t!profile,它将发送两次消息。我发现问题与我创建的过滤器有关。

        if getImmunityValue == 0:
            for word in getWord:
                if getMutedValue == 0:
                    message.content = message.content.lower()
                    if message.content.count(''.join(word)) > 0:
                        id = message.author.id
                        curs.execute('SELECT channelID FROM getchannel')
                        getChannelID = curs.fetchone()[0]

                        channel = self.client.get_channel(getChannelID)

                        curs.execute('SELECT strike FROM user WHERE userID = (%s)', (id,))
                        getstrike = curs.fetchone()[0]

                        curs.execute(f'UPDATE user SET strike = {getstrike + 1} WHERE userID = {id}')
                        db.commit()

                        await message.delete()
                        await message.channel.send(f'{message.author.mention} Bitte benutzte kein Schimpfwoerter. Falls du weiter machen solltest, wirst du gebannt oder gemutet!')

                        Embed = discord.Embed(
                            title=f'{getstrike}x strike(s) from {message.author}',
                            color=discord.Colour.red(),
                            timestamp=self.datetime.utcnow()
                        )

                        Embed.add_field(name='Blacklist Wort:', value=message.content, inline=False)
                        Embed.add_field(name='Channel-ID:', value=message.channel.id, inline=False)
                        Embed.add_field(name='Channel:', value=message.channel, inline=False)

                        await channel.send(embed=Embed)

        await self.client.process_commands(message)

【问题讨论】:

  • 您在on_message 事件中创建命令?你应该使用 discord.py 中的commands 框架,它会简单得多:)
  • 不,我不知道。您看到的代码都在消息事件中

标签: python discord discord.py


【解决方案1】:

所以问题出在await self.client.process_commands(message) 我不知道为什么,但这解决了它。

【讨论】:

  • 在这种情况下self.client.process_commands(message) 会导致命令运行两次
猜你喜欢
  • 2017-08-15
  • 1970-01-01
  • 2020-06-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-04-29
  • 2021-03-18
  • 2012-08-17
相关资源
最近更新 更多