Home>
I wanted to make code for requests to the server using buttons, but I ran into a problem that in @bot.event I need inter and I need ctx, but when you add ctx it gives an error that there is no argument, and when there is no ctx, then problems with the code, because it is used there. Is it possible to somehow replace this or rewrite a little code? I will be grateful for any help. The code itself:
@bot.event
async def on_button_click(inter, ctx):
if inter.component.id== 'zay1':
ticket_created_embed= discord.Embed(
title="Application",
description=f"""Greetings, {ctx.author.name}! Send your **tag*\n to the chat and wait for the administration to reply.""", color=0xff00ff
)
ticket_created_embed.set_footer(text='Congratulations server administration')
overwrites= {
guild.default_role: discord.PermissionOverwrite(view_channel=False),
guild.me: discord.PermissionOverwrite(view_channel=True)}
ticket= await ticket_category.create_text_channel(
f"{ctx.author.name}-{ctx.author.discriminator}", overwrites=overwrites
)
await inter.reply(f'#{ctx.author.name}-{ctx.author.discriminator} -your request channel.', ephemeral=True)
row= ActionRow(Button(style=ButtonStyle.red, label='Close', custom_id='zay2'))
await ticket.send(ctx.author.mention, embed=ticket_created_embed, components=[row])
if inter.component.id== 'zay2':
await ctx.channel.delete()
-
Answer # 1
-
Answer # 2
the point is that you need to separate the code where to be used
ctx
, It's a good idea to write all functions related to ctxin one function, and everything related tointer
to another function@bot.event async def on_button_click(ctx): code here @bot.event async def on_button_click(inter): code here
If I split the code, how can I track which button was clicked by the user so that I can create a channel after clicking it?
Toxa1432022-02-03 09:33:43
Related questions
- python : Running two bots at the same time discord.py
- python : bot ignores arguments
- python : Developing Discord Bots with discord.py
- python : Bot not sending message to PM (Discord.py)
- python : How to make an attachment when sending a message with a site url
- Program for finding synonyms of Russian words python
- python : Logging into your account, reading, sending and editing messages in telegrams via telethon
- python : Instead of one line, everything is deleted!
- Can't uninstall/install Python
the point is that you need to separate the code where to be used
ctx
, It's a good idea to write all functions related to ctxin one function, and everything related tointer
to another functionIf I split the code, how can I track which button was clicked by the user so that I can create a channel after clicking it?
Toxa1432022-02-03 09:33:43