为什么活动重复? Disnake,DiscordPy

问题描述 投票:0回答:1

on_presence_update - 当会员更新其状态时调用。

有代码:

@bot.event()
async def on_presence_update(self,before,after):
    print('test')

并且当用户的状态更新时,消息“测试”被发送2次。即调用2次。为什么?以及如何解决?

我还要补充一点,这种情况不仅发生在本次活动中。

谢谢您的帮助。

python discord discord.py disnake
1个回答
0
投票

通过使用括号和

bot.event
,您不仅可以监听事件然后调用函数,还可以调用装饰器。请参阅带或不带括号的装饰器

就像文档中给出的示例一样,您想要排除括号。

@bot.event
async def on_presence_update(self, before, after):
    print('test')
© www.soinside.com 2019 - 2024. All rights reserved.