#how to make a button role?

1 messages · Page 1 of 1 (latest)

foggy patio
#

sorry if my question is stupid

onyx venture
#

You're using the wrong decorator for slash commands it should be @bot.slash_command()

foggy patio
#

why i cant use ctx command?

#

i dont want to use slask command

#

@onyx venture S

#

?

onyx venture
#

You can, but your code is all over the place

#

What is the problem?

foggy patio
#

idk how to make a button that give role and after that send a message

onyx venture
#

Your code does that as far as i can tell

#

Its a bit wonk, but it should work

foggy patio
#

ik its bat

#

bad*

#

Ignoring exception in on_button_click
Traceback (most recent call last):
File "C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\site-packages\disnake\client.py", line 700, in _run_event
await coro(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
TypeError: help_listener() missing 1 required keyword-only argument: 'inter'

#

theres an error

#

when i clicking on the button

onyx venture
#

call it inter instead of ctx

foggy patio
#

already did, but still dont working

#

@onyx venture

onyx venture
#

Show the code you have now then

foggy patio
#

wait

#
@bot.command()
async def roles(inter: disnake.ApplicationCommandInteraction):
    embed = disnake.Embed(title=None, description="🎉・Для тех кто хочет получать уведомления о новых розыгрышах.\n📰・Для тех кто хочет получать уведомления о новостях всего роблокса и новостей сервера.\n🛒・Для тех кто хочет получать уведомления о новых товарах в лавках.\n\n**___Для того что бы получать уведомления просто нажмите на реакцию ниже___**", color=0xffffff)
    embed.set_author(name="Авто-роли Arigato Gyro", icon_url="https://cdn.discordapp.com/attachments/1015554205873868831/1059542480128843776/IMG_20221126_232925_868.jpg")
    await inter.send(
        embed=embed,
        components=[
            disnake.ui.Button(label="🎉", style=disnake.ButtonStyle.success, custom_id="1"),
            disnake.ui.Button(label="📰", style=disnake.ButtonStyle.green, custom_id="2"),
            disnake.ui.Button(label="🛒", style=disnake.ButtonStyle.success, custom_id="3"),
        ],
    )


@bot.listen("on_button_click")
async def help_listener(User, *, inter: disnake.MessageInteraction):
    if inter.component.custom_id not in ["1", "2", "3", "4", "5", "6", "7", "8", "9", ]:
        # We filter out any other button presses except
        # the components we wish to process.
        return
    
    if inter.component.custom_id == "2":
        news = await disnake.utils.get(iterable=None, guild_id=User.guild.id, role_id=1015694933614657587),
        await inter.send("Вам выдали новую роль!", ephemeral=True),
        inter.user.add_roles(news)
#

@onyx venture

onyx venture
foggy patio
#

or what do u mean? i made it slash command

#

oh

onyx venture
#

In help-listener

foggy patio
#

alr

#

nothing changed

onyx venture
#

What's the error?

foggy patio
#

discord cant see the slash command

#

wait ill send the screenshot

onyx venture
#

You have not made slash command tho. You declared a prefix command

foggy patio
#

ok

#

i thought inter=slash command

onyx venture
#

No @bot.slash_command is slash command

foggy patio
#

Ignoring exception in on_button_click
Traceback (most recent call last):
File "C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\site-packages\disnake\client.py", line 700, in _run_event
await coro(*args, **kwargs)
File "c:\Users\User\Desktop\Guro Bot\Guro.py", line 252, in help_listener
news = await disnake.utils.get(iterable=None, guild_id=user.guild.id, role_id=1015694933614657587),
^^^^^^^^^^
AttributeError: 'Command' object has no attribute 'guild'

onyx venture
#

Role is a @bot.command which is a prefix command

foggy patio
#

k i understood

onyx venture
#

I'm out walking lol, can't remember how the utils.get work but it's not that atleast. Sec

#

Why is User a command?

#

Tag! I'll respond to this in an hour ish when I'm back home. Maybe someone else can jump in

foggy patio
#

k

onyx venture
#

Im back

foggy patio
#

@onyx venture so what i need to do?

onyx venture
#

Send me your entire code now and ill fix it so you can see how its suppose to look

onyx venture
foggy patio
#


@bot.command()
@commands.has_any_role(1036348008780017714)
async def roles(interaction: disnake.ApplicationCommandInteraction):
    embed = disnake.Embed(title=None, description=":tada:・Для тех кто хочет получать уведомления о новых розыгрышах.\n:newspaper:・Для тех кто хочет получать уведомления о новостях всего роблокса и новостей сервера.\n:shopping_cart:・Для тех кто хочет получать уведомления о новых товарах в лавках.\n\n**___Для того что бы получать уведомления просто нажмите на реакцию ниже___**", color=0xffffff)
    embed.set_author(name="Авто-роли Arigato Gyro", icon_url="https://cdn.discordapp.com/attachments/1015554205873868831/1059542480128843776/IMG_20221126_232925_868.jpg")
    await interaction.send(
        embed=embed,
        components=[
            disnake.ui.Button(emoji=":tada:", style=disnake.ButtonStyle.success, custom_id="1"),
            disnake.ui.Button(emoji=":newspaper:", style=disnake.ButtonStyle.green, custom_id="2"),
            disnake.ui.Button(emoji=":shopping_cart:", style=disnake.ButtonStyle.success, custom_id="3"),
        ],
    )


@bot.listen("on_button_click")
async def help_listener(interaction: disnake.MessageInteraction):
    if interaction.component.custom_id not in ["1", "2", "3", "4", "5", "6", "7", "8", "9", ]:
        # We filter out any other button presses except
        # the components we wish to process.
        return
    
    if interaction.component.custom_id == "2":
        news = await disnake.utils.get(guild_id=1013518813142188033, role_id=1015694933614657587),
        await interaction.send("Вам выдали новую роль!", ephemeral=True),
        await interaction.user.add_roles(news) ```
#

@onyx venture

onyx venture
#

And you wanted roles to be a slash command?

foggy patio
#

no

#

i wanna button that give a role

onyx venture
#

Yes, but theres also a command here,

#

@bot.command()
@commands.has_any_role(1036348008780017714)
async def roles(interaction: disnake.ApplicationCommandInteraction):

this

foggy patio
#

yes

onyx venture
#

do you want it to be a slash command or a prefix command?

#

/roles or !roles

foggy patio
#

prefix

onyx venture
#

Is this bot in more than one server?

#

@foggy patio

foggy patio
#

only in one

onyx venture
#
@bot.command()
@commands.has_any_role(1036348008780017714)
async def roles(ctx: commands.Context):
    embed = disnake.Embed(title=None, description=":tada:・Для тех кто хочет получать уведомления о новых розыгрышах.\n:newspaper:・Для тех кто хочет получать уведомления о новостях всего роблокса и новостей сервера.\n:shopping_cart:・Для тех кто хочет получать уведомления о новых товарах в лавках.\n\n**___Для того что бы получать уведомления просто нажмите на реакцию ниже___**", color=0xffffff)
    embed.set_author(name="Авто-роли Arigato Gyro", icon_url="https://cdn.discordapp.com/attachments/1015554205873868831/1059542480128843776/IMG_20221126_232925_868.jpg")
    await ctx.send(
        embed=embed,
        components=[
            disnake.ui.Button(emoji=":tada:", style=disnake.ButtonStyle.success, custom_id="1"),
            disnake.ui.Button(emoji=":newspaper:", style=disnake.ButtonStyle.green, custom_id="2"),
            disnake.ui.Button(emoji=":shopping_cart:", style=disnake.ButtonStyle.success, custom_id="3"),
        ],
    )


@bot.listen("on_button_click")
async def help_listener(interaction: disnake.MessageInteraction):
    if interaction.component.custom_id not in ["1", "2", "3", "4", "5", "6", "7", "8", "9", ]:
        # We filter out any other button presses except
        # the components we wish to process.
        return
    
    if interaction.component.custom_id == "2":

        news = await interaction.guild.get_role(1015694933614657587)
        if news and not news in interaction.user.roles:
            await interaction.user.add_roles(news)
        await interaction.send(f"Вам дали роль: {news.name}", ephemeral=True)

@foggy patio try this

foggy patio
#

k

#

TYSMMMMM

#

@onyx venture

#

THANKSSS

onyx venture
#

🙂 yw

onyx venture
#
    if interaction.component.custom_id == "2":
        news = await interaction.guild.get_role(1015694933614657587)
        if news and not news in interaction.user.roles:
            await interaction.user.add_roles(news)
            await interaction.send(f"Вам дали роль: {news.name}", ephemeral=True)
        else:
            await interaction.send("У вас уже есть эта роль", ephemeral=True)
            #Or you could remove it, so the button works like a reaction role
onyx venture
# foggy patio k

Forgot to add what happens if you already have the role. I suggest you remove it then 🙂
also use better custom id's