I am trying to make a simple discord bot, that gives a role to a user after he gives the bot a certain command

On the command !role the user should get a role called Beta

I first tried this:

from discord_webhook import DiscordWebhook, DiscordEmbed
import discord
from discord.ext.commands import Bot
from discord.ext import commands


client = commands.Bot(command_prefix = "!")
Client = discord.Client()

@client.event
async def on_message(message):
    member = message.author
    if member.bot:
        return
    if message.attachments:
        return
    print(message.content)
    print(str(message.author))


    if "role" in message.content:
        embed=discord.Embed(title="Giving role.", color=0x00ff40)
        await message.channel.send(message.channel, embed=embed)
        role = discord.utils.get(server.roles, name="Beta")
        await client.add_roles(message.author, role)


client.run("BOT TOKEN")

But I always get the following problem: AttributeError: 'list' object has no attribute 'roles'

Thanks a lot for taking time to read this and if you can help me. Thanks

1 Answers

1
Miguel On

When you do:

role = discord.utils.get(server.roles, name="Beta")

You have to use

message.guild.roles

instead of:

server.roles

to access the list of roles, newer discord versions use guild instead of server to avoid confusion with voice servers.