Reputation: 65
I'm trying to make a bot that will do certain things when a member joins the server. More precisely, it has to give them some roles and DM the member.
@client.event
async def on_member_join(member):
roles = {"Level": 705112591927869513, "Interests": 705116168444444773, "Region": 725984087948656710,
"Subscriptions": 705122149152850062}
member_role = discord.utils.get(member.guild.roles, name = "member")
await member.add_roles(member_role)
for role in roles.keys():
newrole = discord.utils.get(member.guild.roles, id = roles[role])
await member.add_roles(newrole)
await member.send("Welcome to the server! Please read the rules and verify yourself to be able to type! "
"Link to jump directly to the message - link")
My issue is that, for reason, it doesn't work consistently. Sometimes it gives all the roles, others just the member one and others none at all. I understand that not all members will get the DM (because of the privacy settings) and that's fine, but I don't really get why not all members get all the roles when they join. Thanks in advance!
Upvotes: 0
Views: 211
Reputation: 4225
This maybe because of the rate limits of Discord API.
This may work
@client.event
async def on_member_join(member):
roles = {"Level": 705112591927869513, "Interests": 705116168444444773, "Region": 725984087948656710,
"Subscriptions": 705122149152850062}
member_role = discord.utils.get(member.guild.roles, name = "member")
await member.add_roles(member_role)
roles = [member.guild.get_role(i) for i in roles.values()]
await member.add_roles(*roles)
await member.send("Welcome to the server! Please read the rules and verify yourself to be able to type! "
"Link to jump directly to the message - link")
Upvotes: 1