K
K
kokapuk2021-08-17 21:17:13
Python
kokapuk, 2021-08-17 21:17:13

Why can't I get server members?

import discord
from discord import message
from discord import member
from discord.ext import commands
import json
import os.path
import datetime
import asyncio
import os

_dict = {}
SAVEPATH = 'MuteData.json'
MUTEROLEID = x
GUILDID = x
MODERATIONROLEID = x
TOKEN = 'X'

MUTEROLE = ''
GUILD = ''
MODERATIONROLE = ''

intents = discord.Intents.all()

bot = commands.Bot(command_prefix='+', intents=intents)

@bot.event
async def on_ready():
    print('invoked')
    global MUTEROLE, GUILD, MODERATIONROLE
    GUILD = await bot.fetch_guild(GUILDID)
    MUTEROLE = GUILD.get_role(MUTEROLEID)
    MODERATIONROLE = GUILD.get_role(MODERATIONROLEID)
    bot.loop.create_task(getMuteList())
    if (not os.path.exists(SAVEPATH)) or (len(_dict) == 0):
        print(GUILD.members)
        for member in GUILD.members:
            if MUTEROLE in member.roles:
                await member.remove_roles(MUTEROLE)

bot.run(TOKEN)


GUILD.members returns an empty list

611bfdd982608513681484.png

Another interesting thing is that the join event to the server fires, although it also, as far as I know, requires intents.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
Zero None, 2021-08-19
@kokapuk

Use get_guild(GUILDID) instead of fetch_guild(GUILDID)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question