@RED2190

Как сделать выдачу роли по нажатию на кнопку в Discrod боте python?

Я хочу, что бы по нажатию на кнопку мне выдавалась роль. Но не могу получить автора нажатия, что бы сделать это. Из документации брал .author но ошибка('InteractionContext' object has no attribute 'author') что такого модуля нет. Вот код не рабочий:

bot = commands.Bot(command_prefix='-', intents=intents)
buttons = ButtonsClient(bot)




# --------------------------------------
@bot.event
async def on_ready():
    print('БОТ ВЫШИЛ В СВЕТ')


@bot.command()
async def vac(ctx):
	text = '**Что бы получить доступ к общению с другими участниками сервера, вакцинируйтесь, для безопасного контакта с другими!!!**'
	emb = discord.Embed(
		title = 'ВАКЦИНАЦИЯ', 
		description = text,
		color = discord.Color.red())
	comp = [
		Button(style = ButtonStyle.green, label = 'Вакцинироваться', custom_id = "vac_b")]
	await ctx.send(embed=emb,components=comp)


@buttons.click
async def vac_b(ctx):
	ch = bot.get_channel(944627342205149254)
	ms = "Вы успешно вакцинировались, добро пожаловать на сервер"
	mem = ctx.author
	await ch.send(f"{ms}, {mem.mention}".format(ctx.name))


Вот рабочий:

import discord
from discord.ext import commands
from discord_components import DiscordComponents, Button, ButtonStyle
from discord.ext import commands, tasks
from discord_components import *
from discord_buttons_plugin import  *
from discord.ext.commands import Bot
from discord import member
import requests

intents = discord.Intents.all()
from discord.ext import commands, tasks
# --------------------------------------
bot = commands.Bot(command_prefix='-', intents=intents)
buttons = ButtonsClient(bot)




# --------------------------------------
@bot.event
async def on_ready():
    print('БОТ ВЫШИЛ В СВЕТ')


@bot.command()
async def vac(ctx):
	text = '**Что бы получить доступ к общению с другими участниками сервера, вакцинируйтесь, для безопасного контакта с другими!!!**'
	emb = discord.Embed(
		title = 'ВАКЦИНАЦИЯ', 
		description = text,
		color = discord.Color.red())
	comp = [
		Button(style = ButtonStyle.green, label = 'Вакцинироваться', custom_id = "vac_b")]
	await ctx.send(embed=emb,components=comp)


@buttons.click
async def vac_b(ctx):
	ch = bot.get_channel(944627342205149254)
	ms = "Вы успешно вакцинировались, добро пожаловать на сервер"
	await ch.send(ms)
  • Вопрос задан
  • 331 просмотр
Решения вопроса 1
MrShandy
@MrShandy
Python
624c0f0aa7488083176162.png
https://github.com/SilentJungle399/discord_buttons...
spoiler
Решили вопрос в комментариях, продублировал тут для тех, кто будет искать
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы