简体   繁体   中英

How I can fix that the bot spams the message?

I want to code a bot event that sends a message to a certain channel whenever a certain person comes online. But when the event is triggered the bot spams the message. how can i fix it?

@bot.event
async def on_member_update(before, after):
    if str(after.status) == "online" and after.id == MyID:
        channel = bot.get_channel (941209391917568000) 
        await channel.send("idk")

Add a check to ensure the string value of after and before are not the same.

Eg change

if str(after.status) == "online" and after.id == MyID:

to

if str(after.status) == "online" and after.id == MyID and str(after.status) !== str(before.status) 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM