1
votes

i am trying to make the bot give the 'mall' role and remove the 'study hall' role. However, it keeps returning the error

Ignoring exception in on_message Traceback (most recent call last): File "C:\Users\frost\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\client.py", line 333, in _run_event await coro(*args, **kwargs) File "D:\GalaxyConflux Master\gcclient.py", line 89, in on_message role.id = 798193741403127818 AttributeError: 'str' object has no attribute 'id'

the code that is running is this

@client.event
async def on_message(message):
    if message.content.startswith(gccmd.cmd_prfx + 'mall'):
        role = 'Mall'
        role.id = 798193741403127818
        await message.author.add_roles(role.id)

i have tried many different approaches but each result in a similar error. I had it just go off of the role = 'Mall' part but that did not work either.

How can I convert the role id into an actual id?

Thanks so much! ~Glimmer

1

1 Answers

0
votes

here's an example peice that shows you how to add a role and remove one.

@client.command()
async def mall(ctx):
    # if prefix is '-' you'd type: -mall
    await user.remove_roles(@ROLE_ID)
    await user.add_roles(@ROLE_ID)
    await ctx.send("Mall role added!")

@client.command()
async def home(ctx):
    # if prefix is '-' you'd type: -home
    await user.remove_roles(@ROLE_ID)
    await user.add_roles(@ROLE_ID)
    await ctx.send("Home role added!") 

If you want to remove multiple roles, you'd have to just add all of the roles there you want to remove, then add the one's you want.

For example, if you are heading to the mall from your house, it removes every role including the house role and adds the mall one.