Why aren't my member variables filled when I use discord.utils.get()?

29 Views Asked by At

The ID-s are the correct 18 number ones from discord, the intents and bot rights are set properly, yet both fetches come back with None.

import discord
from discord.ext import commands

intents = discord.Intents.default()
intents.members = True
bot = commands.Bot(command_prefix='!', intents=intents)

@bot.event
async def on_ready():
    print(f'Logged in as {bot.user.name}')

@bot.event
async def on_member_update(before, after):
    user1 = discord.utils.get(after.guild.members, name="botid")
    user2 = discord.utils.get(after.guild.members, name="myid")

    if after.id == user1.id and before.roles != after.roles and user2 in after.roles:
        roles_added = [role for role in after.roles if role not in before.roles]
        roles_removed = [role for role in before.roles if role not in after.roles]

        if roles_added:
            await after.remove_roles(*roles_added, reason="Automated action: roles cannot be assigned to user1 by user2")
        elif roles_removed:
            await after.add_roles(*roles_removed, reason="Automated action: roles cannot be removed from user1 by user2")

A basic role bot that prevents a specific user(me) to set roles to another user(the bot)

0

There are 0 best solutions below