Detecting Multiple Guild IDs – Discord.py

  discord, discord.py, python, python-3.x

This code works for sending a DM to a user who joined a guild, but it only executes the first if statement instead of actually checking to see what guild the member joined. I’ll get the first DM from the bot whether I join guild1 or guild2.

@client.event
async def on_member_join(member):
    guild1 = client.get_guild(762921541204705321)
    guild2 = client.get_guild(593941391110045697)
    if guild1.id == 762921541204705321:
        await member.create_dm()
        await member.dm_channel.send("Welcome to guild1!")
    elif guild2.id == 593941391110045697:
        await member.create_dm()
        await member.dm_channel.send(f"Welcome to guild2!")

Source: Python Questions

LEAVE A COMMENT