I have an issue with assigning roles to discord users in my server with the bot i created.
The code I made is for interacting with FaceIT, which works fine, but I want to be able to assign roles based on how many matches have been played by a user.
With my Code, I know the IDs of the discord user as they are stored in a config file, and the config is loaded into an array called server_config
When I run the code, I get this error:
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'Guild' object has no attribute 'add_roles'
Here is a sniplet of my code below
@client.command(aliases=["lvl"])
async def assignLvl(ctx):
global server_config
players = server_config[str(ctx.guild.id)]['players']
# Making sure the server is registered
check_server(ctx)
.
.
. this part gets FACEIT data and works
.
.
.
gzk_srvr = ctx.guild
for item in hub_data:
for key in players:
if players[key] == item['nickname']:
if int(item['stats']['Matches']) >= 1 and int(item['stats']['Matches']) < 5:
role = get(gzk_srvr.roles, name="First Scrim Attendee")
user = gzk_srvr.get_member(int(key))
await gzk_srvr.add_roles(players[key], role)
if int(item['stats']['Matches']) >= 5 and int(item['stats']['Matches']) < 15:
role = get(gzk_srvr.roles, name="Lvl 1 Scrimmer")
user = gzk_srvr.get_member(int(key))
await gzk_srvr.add_roles(players[key], role)
if int(item['stats']['Matches']) >= 15 and int(item['stats']['Matches']) < 30:
role = get(gzk_srvr.roles, name="Lvl 2 Scrimmer")
user = gzk_srvr.get_member(int(key))
await gzk_srvr.add_roles(players[key], role)
if int(item['stats']['Matches']) >= 30:
role = get(gzk_srvr.roles, name="Lvl 3 Scrimmer")
user = gzk_srvr.get_member(int(key))
await gzk_srvr.add_roles(players[key], role)
I've seen a few questions and answers on this, and tried implementing them, for example where the OP's answer would be to use await client.add_roles(.....) but i would also get a similar exception thrown
like Bot has no attribute add_roles
I appreciate any help I can get to point me in the right direction.