Home > Blockchain >  Python 3.9.x - Attribute error using discord.py library
Python 3.9.x - Attribute error using discord.py library

Time:11-15

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

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'))

CodePudding user response:

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!

  • Related