I want to tag a person who clicks a button discord.py
Question:
components = [
[
Button(label="Open a ticket", style=2, custom_id="Open", emoji=" ")
]
]
await ctx.send(embed=embed, components=components )
while True:
interaction = await client.wait_for("button_click", check = lambda i: i.component.label.startswith("Open"))
overwrites = {
member_role: discord.PermissionOverwrite(view_channel=False),
ctx.author: discord.PermissionOverwrite(view_channel=True),
guild.me: discord.PermissionOverwrite(view_channel=True),
ticket_mod_role: discord.PermissionOverwrite(view_channel=True)
}
Embed = discord.Embed(
title="Ticket Created",
description=f"{THIS EMPTY SPACE} Your ticket is created",
)
await interaction.send(content = await interaction.send(embed=Embed), ephemeral=True)
ticket = await ticket_category.create_text_channel(
f" │Ticket-{THIS EMPTY SPACE}", overwrites=overwrites
)
Embed = discord.Embed(
title="Ticket Created",
url="",
description=f"""{ctx.author.name} Wait our staff.""",
color=discord.Color.random()
)
Answers:
Instead of ctx.author.name (ctx.author is a discord.member class)
Use ctx.author.mention
Docs:
https://discordpy.readthedocs.io/en/stable/api.html?highlight=mention#discord.Member.mention
i’ve resolved using the library of discord.py (interaction) instead of this i used the object (user.name)
import discord
from discord.ext import commands
from discord_buttons_plugin import *
intents = discord.Intents.default()
intents.members = True
client = commands.Bot(command_prefix='>', intents=intents)
buttons = ButtonsClient(client)
@client.event
async def on_ready():
print("Log : "+str(client.user))
@client.command()
@commands.has_permissions(administrator=True)
async def ticket(ctx):
em = discord.Embed(title="join us",description="To create a ticket react with",emoji={"id": None,"name": " ","animated": False},color=discord.Color.from_rgb(0,255,0))
await buttons.send(embed=em,channel=ctx.channel.id,
components=[ActionRow([Button(style= ButtonType().Secondary,label = "Create ticket",custom_id = "test1")])])
@buttons.click
async def test1(ctx):
guild = ctx.guild
ch = await guild.create_text_channel(name=f'ticket-{ctx.member}')
await ch.set_permissions(ctx.guild.default_role,view_channel=False,send_messages=False)
await ch.set_permissions(ctx.member,view_channel=True,send_messages=True)
await ctx.reply(f"Ticket created {ch.mention}",flags=MessageFlags().EPHEMERAL)
client.run("token")
components = [
[
Button(label="Open a ticket", style=2, custom_id="Open", emoji=" ")
]
]
await ctx.send(embed=embed, components=components )
while True:
interaction = await client.wait_for("button_click", check = lambda i: i.component.label.startswith("Open"))
overwrites = {
member_role: discord.PermissionOverwrite(view_channel=False),
ctx.author: discord.PermissionOverwrite(view_channel=True),
guild.me: discord.PermissionOverwrite(view_channel=True),
ticket_mod_role: discord.PermissionOverwrite(view_channel=True)
}
Embed = discord.Embed(
title="Ticket Created",
description=f"{THIS EMPTY SPACE} Your ticket is created",
)
await interaction.send(content = await interaction.send(embed=Embed), ephemeral=True)
ticket = await ticket_category.create_text_channel(
f" │Ticket-{THIS EMPTY SPACE}", overwrites=overwrites
)
Embed = discord.Embed(
title="Ticket Created",
url="",
description=f"""{ctx.author.name} Wait our staff.""",
color=discord.Color.random()
)
Instead of ctx.author.name (ctx.author is a discord.member class)
Use ctx.author.mention
Docs:
https://discordpy.readthedocs.io/en/stable/api.html?highlight=mention#discord.Member.mention
i’ve resolved using the library of discord.py (interaction) instead of this i used the object (user.name)
import discord
from discord.ext import commands
from discord_buttons_plugin import *
intents = discord.Intents.default()
intents.members = True
client = commands.Bot(command_prefix='>', intents=intents)
buttons = ButtonsClient(client)
@client.event
async def on_ready():
print("Log : "+str(client.user))
@client.command()
@commands.has_permissions(administrator=True)
async def ticket(ctx):
em = discord.Embed(title="join us",description="To create a ticket react with",emoji={"id": None,"name": " ","animated": False},color=discord.Color.from_rgb(0,255,0))
await buttons.send(embed=em,channel=ctx.channel.id,
components=[ActionRow([Button(style= ButtonType().Secondary,label = "Create ticket",custom_id = "test1")])])
@buttons.click
async def test1(ctx):
guild = ctx.guild
ch = await guild.create_text_channel(name=f'ticket-{ctx.member}')
await ch.set_permissions(ctx.guild.default_role,view_channel=False,send_messages=False)
await ch.set_permissions(ctx.member,view_channel=True,send_messages=True)
await ctx.reply(f"Ticket created {ch.mention}",flags=MessageFlags().EPHEMERAL)
client.run("token")