Simple button interaction
This commit is contained in:
parent
cd95cf10ca
commit
7dc712277a
28
bot.py
28
bot.py
|
@ -1,8 +1,8 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
import discord
|
import disnake
|
||||||
from discord.ext import commands
|
from disnake.ext import commands
|
||||||
import logging
|
import logging
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
|
@ -26,12 +26,30 @@ bot = commands.Bot(command_prefix='!')
|
||||||
|
|
||||||
|
|
||||||
@bot.event
|
@bot.event
|
||||||
async def on_message(message):
|
async def on_message(message: disnake.Message):
|
||||||
await bot.process_commands(message)
|
await bot.process_commands(message)
|
||||||
|
|
||||||
|
|
||||||
@bot.command()
|
@bot.command()
|
||||||
async def helloworld(ctx):
|
async def vote(ctx: commands.Context):
|
||||||
await ctx.send("plop")
|
view = Confirm()
|
||||||
|
await ctx.message.reply("plop", view=view)
|
||||||
|
await view.wait()
|
||||||
|
|
||||||
|
|
||||||
|
# Define a simple View that gives us a confirmation menu
|
||||||
|
class Confirm(disnake.ui.View):
|
||||||
|
@disnake.ui.button(label="S'allier", style=disnake.ButtonStyle.green)
|
||||||
|
async def confirm(self, button: disnake.ui.Button, interaction: disnake.MessageInteraction):
|
||||||
|
self.clear_items()
|
||||||
|
await interaction.response.edit_message(content="Vous vous êtes allié.", view=self)
|
||||||
|
self.stop()
|
||||||
|
|
||||||
|
@disnake.ui.button(label="Trahir", style=disnake.ButtonStyle.red)
|
||||||
|
async def cancel(self, button: disnake.ui.Button, interaction: disnake.MessageInteraction):
|
||||||
|
self.clear_items()
|
||||||
|
await interaction.response.edit_message("Vous avez trahi.", view=self)
|
||||||
|
self.stop()
|
||||||
|
|
||||||
|
|
||||||
bot.run(config.discord_token)
|
bot.run(config.discord_token)
|
||||||
|
|
Loading…
Reference in New Issue