> For the complete documentation index, see [llms.txt](https://garagetesla.gitbook.io/discord-bot-python/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://garagetesla.gitbook.io/discord-bot-python/overview/discord-buttons.md).

# Discord buttons

Example to work bu

label - ТекстКнопки , style -  Стиль , view-  сам весь компонент кнопки , content - Текст сообщения

## Create class

<pre><code><strong>class Buttons(discord.ui.View):
</strong>    def __init__(self, *, timeout=180):
        super().__init__(timeout=timeout)
    @discord.ui.button(label="Не тык", style=discord.ButtonStyle.red)
    async def gray_button(self, intel:discord.Interaction,baba:discord.ui.Button):
        baba.style = discord.ButtonStyle.green
        baba.label = "Спасибо , что нажал"
        # await intel.response.edit_message(content="Чувак ты дурак") #изменение текста сообщения - content
        await intel.response.edit_message(view=self,content = "Чувак ты дурак") #изменение кнопки view - через вложженные baba.style и ba
</code></pre>

## Create functions

```
@bot.command(name='кнопка')
async def button(ctx):
    await ctx.send('Нажми на меня', view=Buttons()) 
```

## Full code

```
import discord
from discord.ext import commands, tasks
import os

DISCORD_TOKEN = "MTAyOTcwMDU2OTU0MTEyNDA5Ng.GzWeu9.hUsh3Nj-2B0Dvrqpn6zJwwkirkzJIJ236WBGKs"

intents = discord.Intents.all()
client = discord.Client(intents=intents)
bot = commands.Bot(command_prefix="!", intents=intents)

class Buttons(discord.ui.View):
    def __init__(self, *, timeout=180):
        super().__init__(timeout=timeout)
    @discord.ui.button(label="Не тык", style=discord.ButtonStyle.red)
    async def gray_button(self, intel:discord.Interaction,baba:discord.ui.Button):
        baba.style = discord.ButtonStyle.green
        baba.label = "Спасибо , что нажал"
        await intel.response.edit_message(view=self,content = "Чувак ты дурак") #изменение кнопки view - через вложженные baba.style и baba.label
import os
import webbrowser
class Button_hi(discord.ui.View):
    def __init__(self, *, timeout=180):
        super().__init__(timeout=timeout)
    @discord.ui.button(label="Запустить браузер", style=discord.ButtonStyle.red)
    async def gray_button(self, intel:discord.Interaction,baba:discord.ui.Button):
        baba.style = discord.ButtonStyle.green
        baba.label = "Запустил браузер"
        os.startfile(r"C:/Program Files (x86)/Google/Chrome/Application/chrome.exe")
        await intel.response.edit_message(view=self,content = "Выполнил действие - запустить браузер")
    @discord.ui.button(label="Запустить консоль", style=discord.ButtonStyle.green)
    async def green_button(self, intel: discord.Interaction, baba: discord.ui.Button):
        baba.style = discord.ButtonStyle.red
        baba.label = "Запустил консоль"
        webbrowser.open()
        await intel.response.edit_message(view=self, content="Запустил консоль")
    @discord.ui.button(label="Запустить калькулятор", style=discord.ButtonStyle.blurple)
    async def blue_button(self, intel: discord.Interaction, baba: discord.ui.Button):
        baba.style = discord.ButtonStyle.gray
        baba.label = "Запустил калькулятор"
        await intel.response.edit_message(view=self, content="Выполнил действие - запустил калькулятор")

@bot.command(name='кнопка')
async def button(ctx):
    await ctx.send('Нажми на меня', view=Buttons())
@bot.command(name='кнопка2')
async def button(ctx):
    await ctx.send('Нажми на меня', view=Button_hi())

@bot.command(name='печатай')
async def printing(ctx):
    async with ctx.typing():
        await  ctx.send('Я печатал и печатал')
bot.run(DISCORD_TOKEN)
```
