R
R
rirclear2021-11-21 15:51:18
Python
rirclear, 2021-11-21 15:51:18

How to fix an error when issuing a role by a button in discord?

import discord 
from discord import member
from discord.ext import commands 
from discord_components import DiscordComponents, Button, ButtonStyle



bot = commands.Bot(command_prefix=".", intents=discord.Intents.all())


@bot.event 
async def on_ready():
  DiscordComponents(bot)
  print("бот подключен")


@bot.command()
async def verif(ctx):
  await ctx.send(
    embed=discord.Embed(title="кто вы?"),
    components=[
      Button(style=ButtonStyle.grey, label=" ", custom_id="1", emoji="1️⃣"),
      Button(style=ButtonStyle.grey, label=" ", custom_id="2", emoji="2️⃣"),
      Button(style=ButtonStyle.grey, label=" ", custom_id="3", emoji="3️⃣"),
      Button(style=ButtonStyle.grey, label=" ", custom_id="4", emoji="4️⃣"),
      Button(style=ButtonStyle.grey, label=" ", custom_id="5", emoji="5️⃣")

      

    ]	
  )

  responce = await bot.wait_for("button_click")
  if responce.custom_id == "1":
    role = discord.utils.get(ctx.author.server.roles, id=906979207907778620)
    if not role in ctx.author.roles:
      role = discord.utils.get(ctx.author.guild.roles, id=906979207907778620)
      await member.add_roles(role)

bot.run("token")

619a40fc77690216482719.png

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question