N
N
Noobik20992021-10-20 23:20:27
Python
Noobik2099, 2021-10-20 23:20:27

It is not possible to make it so that when I wrote !role @nick the role was given out. Whatever I write, it is given to me. And yes, I'm a teapot :)?

Here is the code itself. In theory, it should give the role to the one I wrote about, but it doesn’t work like that :(

import discord
from discord.ext import commands
from discord import member, message
from discord.utils import get

client = discord.ext.commands
import ctx as ctx
bot = commands.Bot(command_prefix='!')

@bot.command()
@commands.has_role('SNS')
async def test(ctx):
await ctx.send('oK')

@bot.command(pass_context =True)
@commands.has_role('SNS')
async def role(ctx):
member = ctx.message.author
role = discord.utils.get(member.guild.roles, name='Egg')
await member.add_roles (role)
await ctx.send("Role granted!")

bot.run('TOKEN')

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vindicar, 2021-10-20
@Vindicar

member = ctx.message.author
role = discord.utils.get(member.guild.roles, name='Egg')
await member .add_roles(role)
First get the author of the message (i.e. command sender), then give him role, then you wonder why.
(By the way, why do this as a team? through the discord interface is many times faster).
Well, actually,
async def role(ctx):
You generally do not accept parameters from the command.
Do this:
async def role(ctx, target: discord.Member):
Then discord.py will try to parse the passed argument as a user.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question