Q
Q
QweRez2021-06-11 19:41:15
Python
QweRez, 2021-06-11 19:41:15

How to make the bot issue a role when entering a command?

Tried something like this but it didn't work

import discord
from discord.ext import commands
intents = discord.Intents(messages=True, guilds=True)
intents = discord.Intents.default()
intents.members = True

client = commands.Bot(command_prefix='!', intents=intents)
@client.event
async def on_ready():
    await client.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name="#Общение"))
    print("Bot is ready!")

@client.command()
async def admin(ctx):
  user = ctx.author
  role = discords.utils.get( user.guild.roles, id = 852691194433503232 )
  await user.add_roles(role)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Endora Blackwell, 2021-06-12
@QweRez

1. When writing, a mistake was made in the word discord (Extra s behind)
2. To use discord.utils - you need to import it
separately servers, then set the default ones with users (Easier then to use discord.Intents.all())

import discord
import discord.utils

from discord.ext import commands

intents = discord.Intents(messages=True, guilds=True)
intents = discord.Intents.default()
intents.members = True

client = commands.Bot(command_prefix='!', intents=intents)

@client.event
async def on_ready():
    await client.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name="#Общение"))
    print("Bot is ready!")

@client.command()
async def admin(ctx):
  member = ctx.author
  role   = discord.utils.get(member.guild.roles, id = 852691194433503232)
  
  await member.add_roles(role)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question