#how to make a button role?
1 messages · Page 1 of 1 (latest)
Whats the problem?
You're using the wrong decorator for slash commands it should be @bot.slash_command()
idk how to make a button that give role and after that send a message
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
call it inter instead of ctx
Show the code you have now then
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
Remove user, *,
That event only returns 1 arg, which gets assigned to user. Then it fails because nothing gets assigned to the variable inter you have stated should be there
In help-listener
What's the error?
You have not made slash command tho. You declared a prefix command
No @bot.slash_command is slash command
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'
Role is a @bot.command which is a prefix command
k i understood
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
k
Im back
@onyx venture so what i need to do?
Send me your entire code now and ill fix it so you can see how its suppose to look
or have you not done anything since this
@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
And you wanted roles to be a slash command?
Yes, but theres also a command here,
@bot.command()
@commands.has_any_role(1036348008780017714)
async def roles(interaction: disnake.ApplicationCommandInteraction):
this
yes
prefix
only in one
@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
🙂 yw
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
Forgot to add what happens if you already have the role. I suggest you remove it then 🙂
also use better custom id's