Ask coding questions

← Back to all posts
CAN SOMEONE PLEASE EXPLAIN THIS TO ME
Quackalicious (0)

OKAY WHAT IS THE PROBLEM WITH MESSAGE.AUTHOR.ROLE PLEASE EXPLAIN

Answered by AloegelhiPlaysR (104) [earned 5 cycles]
View Answer
Comments
hotnewtop
AloegelhiPlaysR (104)

That's not how you fetch roles. @SilentSerenity is right. This is how you fetch roles:

array = [];
@bot.command(pass_context=True)  
async def getuser(ctx, role: discord.Role):
    role = discord.utils.get(ctx.message.server.roles, name="mod")
    if role is None:
        await bot.say('There is no "mod" role on this server!')
        return
    empty = True
    for member in ctx.message.server.members:
        if role in member.roles:
            await bot.say("{0.name}: {0.id}".format(member))
            empty = False
            array.append(member.id)
    if empty:
        await bot.say("Nobody has the role {}".format(role.mention))

You can do that than narrow down the specific person you're looking for with checking the position of which the array returns the user in.

if "USER ID" in array:
    # NOw you know that user has <role name>~
AloegelhiPlaysR (104)

I haven't worked with python in a long time

AloegelhiPlaysR (104)

if it doesnt work, i can rewrite it a little @Quackalicious

Quackalicious (0)

No its okay, this was really helpful so I can just adapt it so it works in my code. tysm

SilentSerenity (1)

@AloegelhiPlaysR to be honest i had no idea how to really get roles either, just the amount, so this is pretty helpful to me >.<

Quackalicious (0)

Okay wait so if i just need to find the role and not need any of the other stuff would this work for banning or am I just dumb

@bot.command(pass_context = True)
async def ban(member: discord.Member, days: int = 1):
	async def getuser(ctx, role: discord.Role):
		adminRole = discord.utils.get(ctx.message.server.roles, name="Admin")
		if "449706643710541824" in adminRole:
			await bot.ban(member, days)
		else:
			await bot.say("You don't have permission to use this command.")
AloegelhiPlaysR (104)

Ayy, It's quite complicated for a single role though lol @SilentSerenity

Quackalicious (0)

Wait so does this work and if so then what would the command for this be because the command I'm trying isn't working.

SilentSerenity (1)

That isn't how you fetch roles :/

Quackalicious (0)

oh... then how do you fetch roles