#My Bot Isnt Registering The Correct Role

1 messages · Page 1 of 1 (latest)

silver hinge
#

Ive created a discord account generator bot and ive created a config with roles that are required , the command works when im admin but not when i have the proper role

untold panther
# silver hinge

That str will never be in ctx.author.roles because it's a list of Role objects

#

Convert the ID to an int, get the role with ctx.guild.get_role and then run the check

silver hinge
#

so instead of using the config i state the role directly?

untold panther
#

Get the role ID from your config

#

Then convert it to an int

#

And get the role object

silver hinge
#

its already an int is it not 💀

#

its a string in hte config

#

but i mean the numbers itself is an int

untold panther
silver hinge
#

im slow nvm

untold panther
#

the get_role function receives an int

silver hinge
#

i get what u mean

silver hinge
#

and then do it like that

untold panther
#

Yes, you have to

silver hinge
#

role = get(guild.roles, id=role_id)
and then do

untold panther
#

Why str(ctx.author.roles)

silver hinge
#

well im using two roles here

#

so i can define it like this i dont think

#

cant

untold panther
#

How's that related to doing str(ctx.author.roles)

#

Remove the str()

silver hinge
#

and replace it with?

untold panther
#

Nothing?

silver hinge
#

well im using ctx.respond

untold panther
#

So what

#

Still the same thing

silver hinge
#

im using an if statement i have to follow it by something

#

OR am i just really slow

untold panther
#

I told you to remove the str() function

#

Not the ctx.author.roles

silver hinge
#

ok got it

#

i thank u alot

#

im sorry for being toxic earlier

#

🙂 teting now

#

role = guild.get_role(role_id)
AttributeError: 'int' object has no attribute 'get_role'

#
guild = 1039003856421527552
role = guild.get_role(role_id)```
untold panther
#

You indeed don't know how OOP works

#

Remove whatever guild is

silver hinge
#

Parameters?

untold panther
#
role = ctx.guild.get_role(role_id)
if role in ctx.author.roles: 
     ....```
silver hinge
#

and your right its my 2nd month im just practiing not trying to bother u sir im just really tryna get this work and learn ud ont have to help if im annoying u

untold panther
#

In pycord, you work with OOP, Object Orientated Programming. That means almost everything is a Class with functions.

silver hinge
#

oh so i need to put this inside the class

untold panther
#

no

#

Example

#

You see you receive ctx in your command

#

And then you do ctx.respond to send a message

#

ctx is a big class, with many functions and attributes.

silver hinge
#
role = ctx.guild.get_role(role_id)
    if role not in(ctx.author.roles):
        await ctx.respond(f"You cannot gen {service_name}!", ephemeral=True)
        return```
#

pretty sure i did it right

#

dk why the indent went like that

untold panther
#

if role not in ctx.author.roles

#

What's your thing with wraping ctx.author.roles in brackets

silver hinge
#
@client.slash_command(name="generate", guild_ids=[jsonConfig["guild_id"]])
async def generate(ctx, service_name):
    week_services = ["ranked", "skinned"]
    month_services = ["ranked", "skinned"]
 
    if str(ctx.channel.id) != jsonConfig["gen_channel"]:
        await ctx.respond(f"You can only gen in: <#{jsonConfig['gen_channel']}>", ephemeral=True)
        return
 
    service_name = service_name.lower()
    if service_name not in week_services and service_name not in month_services:
        await ctx.respond("Invalid service name", ephemeral=True)
        return
        
    role = ctx.guild.get_role(role_id)
    if role not in(ctx.author.roles):
        await ctx.respond(f"You cannot gen {service_name}!", ephemeral=True)
        return
 
 
    if not os.path.exists(f"accounts/{service_name}.txt"):
        await ctx.respond(f"We are currently out of {service_name}!", ephemeral=False)
        return
 
 
    data = None
    with open(f"accounts/{service_name}.txt", "r+") as accounts:
        data = accounts.readlines()
        accounts.seek(0)
        accounts.truncate()
        accounts.writelines(data[1:])
    try:
        user = await client.fetch_user(int(ctx.author.id))
        await user.send(embed=generateEmbed(service_name, data, "https://media.giphy.com/media/3o7bufVwr3qbu9qYX6/giphy.gif"))
        await ctx.respond("Account Generated, check your DM")
    except Exception:
        await ctx.respond(f"We are currently out of {service_name}!", ephemeral=True)```
untold panther
#

Try it and see

silver hinge
#

i did

#

same error

untold panther
#

What error

silver hinge
#

not and error

#

issue i meant

#

You dont have to help sir if im bothering u i can be patient

#

just trying my best to get this up 🙂

untold panther
#

Do you have such role

silver hinge
#

yes i have such role

untold panther
#

Where did you define role_id

silver hinge
#

wait

#

now it has another issue

#

wtf

#

files filled

#

Crying how does fixing one issue cause another

silver hinge
untold panther
#

service_name is ranked while your file is Ranked

silver hinge
#

changed them and still no difference

untold panther
#

You changed what exactly

silver hinge
untold panther
#

And is it in such path?

silver hinge
#

the bot was working with the default code that slukki or whatever there name was help me make

#

but its cause i had Administrator

silver hinge
untold panther
#

No idea tbh

#

I don't use json as a database

#

I'd just switch to an actual db

silver hinge
#

i need it working

#

idk why