Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python 3.9.x – Attribute error using discord.py library

Creating a simple admissions system – want it to give a role when the person runs a command

Full error feed

Ignoring exception in on_message
Traceback (most recent call last):
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 343, in _run_event
    await coro(*args, **kwargs)
  File "main.py", line 18, in on_message
    await client.add_roles(message.author, role)
AttributeError: 'Client' object has no attribute 'add_roles'

Full code

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

import discord
from discord.utils import get
import os

client = discord.Client()

@client.event
async def on_ready():

  print('we are logged in as {0.user}'.format(client))

@client.event
async def on_message(message):
    if message.author == client.user:
        return
    if message.content == 'give me admin':
        role = get(message.guild.roles, name='Hoplite')
        await client.add_roles(message.author, role)

client.run(os.getenv('Token'))

>Solution :

There isn’t anything like client.add_roles you have to user member.add_roles instead.

await message.author.add_roles(role)

Remember that the bot has to have permissions and the role you want to give has to be lower than the highest role the bot has!

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading