#How to get a member by user id?
1 messages · Page 1 of 1 (latest)
also at the code?
^
?tag intents
https://docs.pycord.dev/en/master/intents.html
https://discord.com/developers/docs/topics/gateway#gateway-intents
import discord
from discord.ext import commands
# Get specific intents for fine control
intents = discord.Intents()
intents.emojis = True
intents.guilds = True
intents.messages = True # Required for prefix commands!
...
# Get all non-priveliged intents; this excludes presences, members and message_content
intents = discord.Intents.default()
# Set priveliged intents: these must be enabled on dev portal
intents.members = True
intents.presences = True
intents.message_content = True # Required for prefix commands >= 2.0.0b5
# Get all intents; all intents must be enabled on dev portal.
intents = discord.Intents.all()
# Apply intents when creating your bot
bot = commands.bot(prefix="?", intents=intents)
In version 1.5 comes the introduction of Intents. This is a radical change in how bots are written. An intent basically allows a bot to subscribe to specific buckets of events. The events that corr...
Integrate your service with Discord — whether it's a bot or a game or whatever your wildest imagination can come up with.
yeah
int userid?
yeah cuz basically storing the user id in a db (stored as str)
yeah but you removed the int conversion
what do you mean by that
yeah
allgood
await
how can i await this, when im not in async function
you don't...
why are you trying to do it out of async
^
cuz its on loop
while True:
please
don't
One of the most common operations when making a bot is having a loop run in the background at a specified interval. This pattern is very common but has a lot of things you need to look out for: How...
it's fine
try fetch_member
its the server request that return None
than you dont have a guild
for what do you need this?
@kind canopy do you have any cause of this error?
fetch a guild, then fetch a certain member (by user id) then give him a roles
.
fetch a guild, then fetch a certain member (by user id) then give him a roles
in a task?
yes
@tasks.loop(seconds=2)
async def role():
roletable = json.load(open('./db/roles.json'))
for userid in roletable:
#print(userid)
userdata = roletable.get(userid)
for guild in userdata:
guildz = userdata.get(guild)
for guild in guildz:
for role in guildz.get(guild):
print(guild)
server = bot.get_guild(int(guild))
member = server.fetch_member(member_id=int(userid))
if member:
print('OMG WE FOUND IT FINALLY')
member.add_roles(1071892798288175195)
@role.after_loop
async def afterloop():
pass
role.start()```
@kind canopy got any solution to this?
and printing bot.guilds is fine?
and not the loop variables
fetching is pointless because a fetched guild doesn't include members
well i guess if you fetch the member then it doesn't matter anyway
how should i do it?
@kind canopy
does await bot.fetch_guild work in that scenario?
