Skip to content
This repository has been archived by the owner on Dec 18, 2021. It is now read-only.

Create simple.py #40

Merged
merged 1 commit into from
May 29, 2021
Merged

Create simple.py #40

merged 1 commit into from
May 29, 2021

Conversation

notnotrachit
Copy link
Contributor

PR TYPE

Added example file. I'm planning to add more examples like calculator, etc

Why did you open this PR (If it is other, please write a more detailed description.)

  • New feature
  • Fix bug
  • Typo
  • Other

Checks

  • Did you use the black formatter?
  • Does this requires the users to change their code?
  • Did you test?
  • Have you updated the docs?
  • Can you listen to our requests?
  • Did you use conventional commits

@PythonSerious
Copy link
Contributor

PythonSerious commented May 28, 2021

Hey, I went ahead and added some small touches to your file! @rachit1601

import discord
from discord.ext import commands
from discord_components import DiscordComponents, Button, ButtonStyle, InteractionType

bot = commands.Bot("!")




@bot.event
async def on_ready():
    #DiscordComponents(bot)
    #^ uncomment this to init discord-components when the bot is ready.
    print(f'Logged in as {bot.user}!')


@bot.command()
async def button(ctx):
    m = await ctx.send("Here is an example of a button",
            components=[[
                Button(style=ButtonStyle.red, label="EMOJI", emoji="😂", disabled=True),
                Button(style=ButtonStyle.green, label="GREEN"), Button(style=ButtonStyle.red, label="RED"),
                Button(style=ButtonStyle.grey, label="GREY"), ],

                Button(style=ButtonStyle.blue, label="BLUE"),
                Button(style=ButtonStyle.URL, label="URL", url="https://www.example.com"),
             ])


@bot.event
async def on_button_click(m):
    DiscordComponents(bot)
    #^ Inits discordcomponents when the event is fired..
    """Possible interaction types:
        Pong
        ChannelMessageWithSource
        DeferredChannelMessageWithSource
        DeferredUpdateMessage
        UpdateMessage

    """
    await m.respond(

        type=InteractionType.ChannelMessageWithSource,
        content=f'{m.component.label} pressed'
    )


bot.run('TOKEN')

@kiki7000
Copy link
Collaborator

Could you put ddb = DiscordComponents(bot) this on the on_ready event?
And you can remove the ddb =

@PythonSerious
Copy link
Contributor

PythonSerious commented May 29, 2021

Could you put ddb = DiscordComponents(bot) this on the on_ready event?
And you can remove the ddb =
@kiki7000 Something like this?

import discord
from discord.ext import commands
from discord_components import DiscordComponents, Button, ButtonStyle, InteractionType

bot = commands.Bot("!")




@bot.event
async def on_ready():
    #DiscordComponents(bot)
    #^ uncomment this to init discord-components when the bot is ready.
    print(f'Logged in as {bot.user}!')


@bot.command()
async def button(ctx):
    m = await ctx.send("Here is an example of a button",
            components=[[
                Button(style=ButtonStyle.red, label="EMOJI", emoji="😂", disabled=True),
                Button(style=ButtonStyle.green, label="GREEN"), Button(style=ButtonStyle.red, label="RED"),
                Button(style=ButtonStyle.grey, label="GREY"), ],

                Button(style=ButtonStyle.blue, label="BLUE"),
                Button(style=ButtonStyle.URL, label="URL", url="https://www.example.com"),
             ])


@bot.event
async def on_button_click(m):
    DiscordComponents(bot)
    #^ Inits discordcomponents when the event is fired.
    """Possible interaction types:
        Pong
        ChannelMessageWithSource
        DeferredChannelMessageWithSource
        DeferredUpdateMessage
        UpdateMessage

    """
    await m.respond(

        type=InteractionType.ChannelMessageWithSource,
        content=f'{m.component.label} pressed'
    )


bot.run('TOKEN')

@kiki7000
Copy link
Collaborator

Without comment

@PythonSerious
Copy link
Contributor

PythonSerious commented May 29, 2021

Without comment
@kiki7000 Here you go!

import discord
from discord.ext import commands
from discord_components import DiscordComponents, Button, ButtonStyle, InteractionType

bot = commands.Bot("!")




@bot.event
async def on_ready():
    DiscordComponents(bot)
    print(f'Logged in as {bot.user}!')


@bot.command()
async def button(ctx):
    m = await ctx.send("Here is an example of a button",
            components=[[
                Button(style=ButtonStyle.red, label="EMOJI", emoji="😂", disabled=True),
                Button(style=ButtonStyle.green, label="GREEN"), Button(style=ButtonStyle.red, label="RED"),
                Button(style=ButtonStyle.grey, label="GREY"), ],

                Button(style=ButtonStyle.blue, label="BLUE"),
                Button(style=ButtonStyle.URL, label="URL", url="https://www.example.com"),
             ])


@bot.event
async def on_button_click(m):
    DiscordComponents(bot)
    #^ Inits discordcomponents when the event is fired.
    """Possible interaction types:
        Pong
        ChannelMessageWithSource
        DeferredChannelMessageWithSource
        DeferredUpdateMessage
        UpdateMessage

    """
    await m.respond(

        type=InteractionType.ChannelMessageWithSource,
        content=f'{m.component.label} pressed'
    )


bot.run('TOKEN')

@kiki7000
Copy link
Collaborator

you don't have to put DiscordComponents(bot) inside on_button_click
And it would be better if the Examples folder starts with lowercase like other folders

@PythonSerious
Copy link
Contributor

PythonSerious commented May 29, 2021

you don't have to put DiscordComponents(bot) inside on_button_click
And it would be better if the Examples folder starts with lowercase like other folders

Well this isnt my pull, i was just editing some things but ill fix that in my pull request which you can go see here

Here is the modified simple.py:

import discord
from discord.ext import commands
from discord_components import DiscordComponents, Button, ButtonStyle, InteractionType

bot = commands.Bot("!")




@bot.event
async def on_ready():
    DiscordComponents(bot)
    print(f'Logged in as {bot.user}!')


@bot.command()
async def button(ctx):
    m = await ctx.send("Here is an example of a button",
            components=[[
                Button(style=ButtonStyle.red, label="EMOJI", emoji="😂", disabled=True),
                Button(style=ButtonStyle.green, label="GREEN"), Button(style=ButtonStyle.red, label="RED"),
                Button(style=ButtonStyle.grey, label="GREY"), ],

                Button(style=ButtonStyle.blue, label="BLUE"),
                Button(style=ButtonStyle.URL, label="URL", url="https://www.example.com"),
             ])


@bot.event
async def on_button_click(m):
    """Possible interaction types:
        Pong
        ChannelMessageWithSource
        DeferredChannelMessageWithSource
        DeferredUpdateMessage
        UpdateMessage

    """
    await m.respond(

        type=InteractionType.ChannelMessageWithSource,
        content=f'{m.component.label} pressed'
    )


bot.run('TOKEN')

@kiki7000 kiki7000 merged commit c81054e into woohyunjng:master May 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants