Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python code button with discord.py

#hi my name is Yahya and today im going to show you how to create a button with libarry discord.py

# First Install discord.py from cmd and run vsc and create anew file

# and type that commands

import discord
from discord.ext import commands
from discord.ui import Buttons,View # this command will allow to you to create and view buttons for members on discord
# run the bot
intents = disocrd.Intents().all() 
intents.message_content = True
# the prefix is for run the command for example #
bot = commands.Bot(command_prefix="#", intents=intents)
# now we will start with create button:
@bot.command()
async def button(ctx):
  button = Button(label="Click for lock channel", style=disocrd.ButtonStyle.red)
  async def button_callback(interaction):
    await ctx.channel.set_permissions(ctx.guild.default_role, send_messages=False)
    await ctx.send("DOne")
# you can make 2 buttons for lock/unlock channel and if u want to send embeds or send messages from buttons just type : interaction.response.send_message(the message with "")
  button.callback = button_callback
  view = View()
  view.add_item(button)
  await ctx.send("this is for grepper", view=view)
  
  bot.run("token")
 
PREVIOUS NEXT
Tagged: #python #code #button
ADD COMMENT
Topic
Name
2+7 =