File: layout.py

package info (click to toggle)
python-discord 2.6.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,476 kB
  • sloc: python: 49,910; javascript: 363; makefile: 154
file content (50 lines) | stat: -rw-r--r-- 1,517 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# This example requires the 'message_content' privileged intent to function.

from discord.ext import commands

import discord


class Bot(commands.Bot):
    # Suppress error on the User attribute being None since it fills up later
    user: discord.ClientUser

    def __init__(self):
        intents = discord.Intents.default()
        intents.message_content = True

        super().__init__(command_prefix=commands.when_mentioned_or('$'), intents=intents)

    async def on_ready(self):
        print(f'Logged in as {self.user} (ID: {self.user.id})')
        print('------')


# Define a LayoutView, which will allow us to add v2 components to it.
class Layout(discord.ui.LayoutView):
    # you can add any top-level component (ui.ActionRow, ui.Section, ui.Container, ui.File, etc.) here

    action_row = discord.ui.ActionRow()

    @action_row.button(label='Click Me!')
    async def action_row_button(self, interaction: discord.Interaction, button: discord.ui.Button):
        await interaction.response.send_message('Hi!', ephemeral=True)

    container = discord.ui.Container(
        discord.ui.TextDisplay(
            'Click the above button to receive a **very special** message!',
        ),
        accent_colour=discord.Colour.blurple(),
    )


bot = Bot()


@bot.command()
async def layout(ctx: commands.Context):
    """Sends a very special message!"""
    await ctx.send(view=Layout())  # sending LayoutView's does not allow for sending any content, embed(s), stickers, or poll


bot.run('token')