Verify Button - Adding Roles with Buttons | discord.py

  Рет қаралды 11,530

Digiwind

Digiwind

Күн бұрын

Пікірлер: 26
@Nevvyboi
@Nevvyboi 2 жыл бұрын
amazing keep it up bro
@pilot_vr9458
@pilot_vr9458 2 жыл бұрын
Its saying role_id and guild_id is not defined? What should i define it to?
@ManiacStories
@ManiacStories 2 жыл бұрын
i can't understand how this will work in cogs please someone give me an example
@gilad7964
@gilad7964 2 жыл бұрын
the button doesnt work after a code restart i did it right
@Digiwind
@Digiwind 2 жыл бұрын
Can you double check? The button works after a restart for me.
@cagberkmarasl148
@cagberkmarasl148 2 жыл бұрын
hi, I'm using nextcord. What can be written instead of "type(Client.role)"?
@Digiwind
@Digiwind 2 жыл бұрын
Replace “Client” with your nextcord bot object. Be sure to declare the variable somewhere, though!
@dev1310
@dev1310 2 жыл бұрын
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_
@_holyhustler_ 2 жыл бұрын
Nice tutorial but how do you make multiple buttons ? If I duplicate @discord.ui.button only the last is displayed.
@Digiwind
@Digiwind 2 жыл бұрын
They should work.. are you button names and custom IDs different?
@_holyhustler_
@_holyhustler_ 2 жыл бұрын
@@Digiwind Yes, I paste the code on pastebin with id bLzbu5NM (youtube block the link)
@Digiwind
@Digiwind 2 жыл бұрын
Can you join our discord (link is in the description) and send your code in the Python channel?
@Staninna
@Staninna 2 жыл бұрын
# 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
@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_top
@konfuze_top 2 жыл бұрын
@@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.
@Digiwind
@Digiwind 2 жыл бұрын
That’s normal.
@alebilly20100
@alebilly20100 2 жыл бұрын
Make a video, when you click the button changes color and label in the button
@れゐと-y9e
@れゐと-y9e 2 жыл бұрын
Is it possible to add more buttons?
@Digiwind
@Digiwind 2 жыл бұрын
Definitely, simply add another button decorator after the first.
@れゐと-y9e
@れゐと-y9e 2 жыл бұрын
​@@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.)
Coding a Basic Ticket | Ticketing in Discord.py (Part 1)
5:52
The evil clown plays a prank on the angel
00:39
超人夫妇
Рет қаралды 53 МЛН
She made herself an ear of corn from his marmalade candies🌽🌽🌽
00:38
Valja & Maxim Family
Рет қаралды 18 МЛН
Modern Graphical User Interfaces in Python
11:12
NeuralNine
Рет қаралды 1,6 МЛН
How I make bots using python (educational)
17:12
Kian Brose
Рет қаралды 572 М.
Discord Bot with Python - Tutorial 4 - Roles Bot
27:05
thenewboston
Рет қаралды 16 М.
Per Server Custom Prefixes in Discord.py with PostgreSQL and asyncpg
8:36
The evil clown plays a prank on the angel
00:39
超人夫妇
Рет қаралды 53 МЛН