首页 > 解决方案 > Discord.py 重复消息

问题描述

我用 cogs 在 discord py 上写 bot。

主要的:

intents = discord.Intents.all()
client = discord.Bot(command_prefix = '$', intents = intents)

for files in os.listdir('./cogs'):
    if files.endswith('.py'):
        client.load_extension(f'cogs.{files[:-3]}')

token = os.environ.get('token')
client.run(token, bot=True)

和齿轮:

class textCommands(commands.Cog):
    def __init__(self, client):
        self.client = client


    @commands.command()
    async def ping(self, ctx):
        await ctx.send(f'Pong! {round(self.client.latency * 1000)}ms')

def setup(client):
    client.add_cog(textCommands(client))

如果我发送“ping”,我的机器人会发送两条消息,我更改了我的令牌,但问题仍然存在。

标签: python-3.xherokudiscord.py-rewrite

解决方案


所以,我找到了答案。我await self.client.process_commands(message)从我的代码中删除并且两次消息丢失


推荐阅读