#My Bot Isnt Registering The Correct Role
1 messages · Page 1 of 1 (latest)
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
Okay,
so instead of using the config i state the role directly?
Get the role ID from your config
Then convert it to an int
And get the role object
its already an int is it not 💀
its a string in hte config
but i mean the numbers itself is an int
This looks like a string
im slow nvm
the get_role function receives an int
i get what u mean
could i define the role
and then do it like that
Yes, you have to
role = get(guild.roles, id=role_id)
and then do
Why str(ctx.author.roles)
and replace it with?
Nothing?
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)```
role = ctx.guild.get_role(role_id)
if role in ctx.author.roles:
....```
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
In pycord, you work with OOP, Object Orientated Programming. That means almost everything is a Class with functions.
oh so i need to put this inside the class
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.
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
if role not in ctx.author.roles
What's your thing with wraping ctx.author.roles in brackets
@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)```
Try it and see
What error
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 🙂
Do you have such role
yes i have such role
Where did you define role_id
wait
now it has another issue
wtf
files filled
how does fixing one issue cause another
it was assigned at the top of the code
service_name is ranked while your file is Ranked
changed them and still no difference
You changed what exactly
And is it in such path?
the bot was working with the default code that slukki or whatever there name was help me make
but its cause i had Administrator
