T
T
Telmor2021-09-23 21:31:10
Python
Telmor, 2021-09-23 21:31:10

How to understand who clicked on a button in discord.py?

I have a command:

i = False

@bot.command(aliases=['t2'])
#@commands.has_any_role(890220161943097404)
async def testinfinitybutton(ctx):
    emb = discord.Embed(title='Нажмите на кнопку')
    emb.set_thumbnail(url=ctx.author.avatar_url)
    msg = await ctx.send(embed = emb,
        components = [
            Button(style=ButtonStyle.gray, label='Роль', emoji='')
        ])
    while i == False:
        responce = await bot.wait_for('button_click')
        if responce.component.label == 'Роль':
            await responce.respond(content="держи свою роль)")

And I need to give the user a role at the click of a button.
That's the crux of the matter.
How to understand who clicked on the button, the author or not?
And after the definition, give this person a role.

My imports
import discord
from discord.embeds import Embed
from discord.ext import commands
from discord.ext.commands import Bot
from discord import member
import asyncio
import os
import string
import json
from discord import Activity, ActivityType
from discord.utils import *
import io
import time
import string
from discord_components import *
from dislash import *
import requests
import random
import re


I will be very happy if I get an answer quickly.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Nevzorov, 2021-09-24
@fixator10

  1. We look at what arguments the button_click event produces .
  2. We read the documentation for the received object .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question