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

Discord.py- Give role to a user

I am trying to give a user a role using the discord.py, but I keep getting the same error.
discord.ext.commands.errors.MissingRequiredArgument: role is a required argument that is missing.

from discord.ext import commands
from discord.utils import get
import discord
import methods

# Intents
intents = discord.Intents.default()
intents.message_content = True
intents.members = True

# Object for discord
client = discord.Client(intents=intents)


bot = commands.Bot(command_prefix='/', intents=intents)
TOKEN = 'active_token'

channel_name = 'ladder'
role_name = 'Ladder Participant'

@bot.command()
async def join_ladder(ctx, role: discord.Role, user: discord.Member):
    """
    This command lets you join the ladder.

    !join_ladder
    """

    if methods.check_ladder_active(): # Method returns True or False
        role = discord.utils.get(user.guild.roles, name=role_name)
        await user.add_roles(role)
        await ctx.send('You are now apart of the ladder.')
        # ADD USERS NAME TO ACTUAL LADDER
    else:
        await ctx.send('Ladder is inactive.')


@bot.command()
async def leave_ladder(ctx, user: discord.Member):
    """
    This command lets you leave the ladder:

    !leave_ladder
    """
    if methods.check_ladder_active():
        role = ctx.guild.get_role('1055287896376082463')  # add role id
        await user.remove_roles(role)
        await ctx.send('You are no longer apart of the ladder.')
        # REMOVE USER FROM LADDER FILE
    else:
        ctx.send('Ladder is inactive')

I have tried two different ways of giving the user the role, the !join_ladder is the most recent way I’ve tried and the !leave_ladder was the first way but instead of user.remove_roles(role) it was user.add_roles(role).

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

>Solution :

The problem is that your commands have required arguments that you didn’t provide when calling them, like this command:

async def join_ladder(ctx, role: discord.(Role, user: discord.Member):

The role and user arguments are required, so when you’re just calling the command like this (prefix) join_ladder, discord.py cannot find the required arguments because they’re missing. The most simple way to fix this is to just remove the arguments that you’re not using in your function or provide them when using the command.

async def join_ladder(ctx, user: discord.Member):

Here is an relevant example.

Also, I see that you have both discord.Client and discord.ext.commands.Bot instance, please pick one of them and remove the other.

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