Its saying role_id and guild_id is not defined? What should i define it to?
@ManiacStories2 жыл бұрын
i can't understand how this will work in cogs please someone give me an example
@gilad79642 жыл бұрын
the button doesnt work after a code restart i did it right
@Digiwind2 жыл бұрын
Can you double check? The button works after a restart for me.
@cagberkmarasl1482 жыл бұрын
hi, I'm using nextcord. What can be written instead of "type(Client.role)"?
@Digiwind2 жыл бұрын
Replace “Client” with your nextcord bot object. Be sure to declare the variable somewhere, though!
@dev13102 жыл бұрын
I would like the button to activate a command automatically is this possible? I saw an example of doing ctx.invoke(self.bot_command) or something but since this is tree sync I don't know the alternative. Thank you!
@_holyhustler_2 жыл бұрын
Nice tutorial but how do you make multiple buttons ? If I duplicate @discord.ui.button only the last is displayed.
@Digiwind2 жыл бұрын
They should work.. are you button names and custom IDs different?
@_holyhustler_2 жыл бұрын
@@Digiwind Yes, I paste the code on pastebin with id bLzbu5NM (youtube block the link)
@Digiwind2 жыл бұрын
Can you join our discord (link is in the description) and send your code in the Python channel?
@Staninna2 жыл бұрын
# Ping command def ping(self, slashes): @slashes.command(name="ping", description="Pong!") async def ping(interaction: discord.Interaction): ping_view = discord.ui.View() ping_button = discord.ui.Button( label="Pong!", style=discord.ButtonStyle.primary, custom_id="ping", ) # Ping callback async def ping_callback(interaction): # Edit message to pong await interaction.response.edit_message( content=f"Ping! random.random() = {rand.random()}", view=rand.choice([ping_view, pong_view]), ) ping_button.callback = ping_callback ping_view.add_item(ping_button) pong_view = discord.ui.View() pong_button = discord.ui.Button( label="Ping!", style=discord.ButtonStyle.primary, custom_id="pong", ) async def pong_callback(interaction): # Edit message to pong await interaction.response.edit_message( content=f"Pong! random.random() = {rand.random()}", view=rand.choice([ping_view, pong_view]), ) pong_button.callback = pong_callback pong_view.add_item(pong_button) # Send pong with random view (ping or pong) and random.random() as content await interaction.response.send_message( f"Pong! random.random() = {rand.random()}", view=rand.choice([ping_view, pong_view]), ) This is my ping command imports import random as rand import discord I have my bot wierdly setup tho with a seprite class for my slash commands
@Ligyb Жыл бұрын
AttributeError: 'Button' object has no attribute 'user'
@ВиталийПунтиков2 жыл бұрын
Traceback (most recent call last): File line 2, in from discord import app_commands ImportError: cannot import name 'app_commands' from 'discord' (C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\__init__.py)
@ВиталийПунтиков2 жыл бұрын
Как это можно исправить?
@konfuze_top2 жыл бұрын
@@Digiwind wow, do you speak russian? or google translate?)))
@ВиталийПунтиков2 жыл бұрын
@@Digiwind Новая проблема появилась [2022-06-15 14:30:43] [INFO ] discord.client: logging in using static token [2022-06-15 14:30:44] [INFO ] discord.gateway: Shard ID None has sent the IDENTIFY payload. [2022-06-15 14:30:45] [INFO ] discord.gateway: Shard ID None has connected to Gateway (Session ID: f8e785214c800ac917e1fb1065738587).
@ВиталийПунтиков2 жыл бұрын
@@Digiwind import discord from discord import app_commands class button_view(discord.ui.View): def __init__(self) -> None: super().__init__(timeout = None) @discord.ui.button(label = "verify", style = discord.ButtonStyle.green, custom_id = "verify") async def verify(self, interaction: discord.Interaction, button: discord.ui.Button): if type(client.role) is not discord.Role: client.role = interaction.guild.get_role(980107923646722068) if client.role not in interaction.user.roles: await interaction.user.add_roles(client.role) await interaction.response.send_message(f"I have given you {client.role.mention}!", ephemeral = True) else: await interaction.response.send_message(f"You already have {client.role.metion}!", ephemeral = True) class aclient(discord.Client): def __init__(self): super().__init__(intents = discord.Intents.default()) self.synced = False self.role = 980107923646722068 self.added = False async def on_ready(self): await self.wait_until_ready() if not self.synced: # self.synced = True if not self.added: self.add_view(button_view()) self.added = True print(f"We have logged in as {self.user}.") client = aclient() tree = app_commands.CommandTree(client) @tree.command(guild = discord.Object(id=979417086570930186), name = 'button', description='Launches role button') async def button(interaction: discord.Interaction): await interaction.response.send_message(view = button_view()) client.run('my token') error and nothing starts: [2022-06-15 21:42:48] [INFO ] discord.client: logging in using static token [2022-06-15 21:42:49] [INFO ] discord.gateway: Shard ID None has sent the IDENTIFY payload. [2022-06-15 21:42:50] [INFO ] discord.gateway: Shard ID None has connected to Gateway (Session ID: 6f6873310493c7a3ba00aa145fdf20bc1). We have logged in as Test1#1278.
@Digiwind2 жыл бұрын
That’s normal.
@alebilly201002 жыл бұрын
Make a video, when you click the button changes color and label in the button
@れゐと-y9e2 жыл бұрын
Is it possible to add more buttons?
@Digiwind2 жыл бұрын
Definitely, simply add another button decorator after the first.
@れゐと-y9e2 жыл бұрын
@@Digiwind As a result of duplicating the decorator and changing "custom_id" and "async defverify" to aliases, I was able to add the button properly. Thank you. (I'm Japanese, so I use Google Translate.)