mirror of
https://code.lenaisten.de/Lenaisten/lenaverse-bot.git
synced 2024-11-23 23:43:01 +00:00
Test dummy "post" app_command
This commit is contained in:
parent
ad7350b4c1
commit
20da5bd078
3 changed files with 55 additions and 18 deletions
|
@ -1,7 +1,7 @@
|
|||
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
|
||||
// README at: https://github.com/devcontainers/templates/tree/main/src/python
|
||||
{
|
||||
"name": "Python 3",
|
||||
"name": "LEVbot",
|
||||
"build": {
|
||||
"dockerfile": "Dockerfile",
|
||||
"context": "..",
|
||||
|
|
|
@ -1,27 +1,30 @@
|
|||
import logging
|
||||
|
||||
import discord
|
||||
from discord.ext.commands import Bot
|
||||
|
||||
from .commands import foo, ping
|
||||
from .commands import post
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class LenaverseBot(Bot):
|
||||
class LenaverseBot(discord.Client):
|
||||
def __init__(self) -> None:
|
||||
intents = discord.Intents.default()
|
||||
intents.message_content = True
|
||||
|
||||
super().__init__(
|
||||
command_prefix="!",
|
||||
intents=intents,
|
||||
)
|
||||
super().__init__(intents=intents)
|
||||
|
||||
self.add_command(ping)
|
||||
self.add_command(foo)
|
||||
self.tree = discord.app_commands.CommandTree(self)
|
||||
self.tree.add_command(post)
|
||||
|
||||
async def setup_hook(self):
|
||||
await self.tree.sync()
|
||||
_logger.info("Commands synced")
|
||||
|
||||
async def on_ready(self) -> None:
|
||||
_logger.info(self.guilds)
|
||||
assert self.user is not None
|
||||
|
||||
if self.user is None:
|
||||
return
|
||||
|
||||
_logger.info(f"{self.user.name} has connected to Discord!")
|
||||
|
|
|
@ -1,11 +1,45 @@
|
|||
from discord.ext import commands
|
||||
import discord
|
||||
from discord import ui
|
||||
|
||||
|
||||
@commands.hybrid_command()
|
||||
async def ping(ctx: commands.Context):
|
||||
await ctx.send("pong")
|
||||
# Define a simple View that gives us a confirmation menu
|
||||
class Confirm(ui.View):
|
||||
value: bool | None = None
|
||||
|
||||
@ui.button(label="Confirm", style=discord.ButtonStyle.green)
|
||||
async def confirm(self, interaction: discord.Interaction, button: ui.Button):
|
||||
await interaction.response.edit_message(content="Confirming", view=None)
|
||||
self.value = True
|
||||
self.stop()
|
||||
|
||||
@ui.button(label="Cancel", style=discord.ButtonStyle.grey)
|
||||
async def cancel(self, interaction: discord.Interaction, button: ui.Button):
|
||||
await interaction.response.edit_message(content="Cancelling", view=None)
|
||||
self.value = False
|
||||
self.stop()
|
||||
|
||||
|
||||
@commands.hybrid_command()
|
||||
async def foo(ctx: commands.Context, arg: str):
|
||||
await ctx.send(arg)
|
||||
class PostModal(ui.Modal, title="foobar2000"):
|
||||
content = ui.TextInput(
|
||||
label="Hier könnte Ihre Werbung stehen",
|
||||
style=discord.TextStyle.long,
|
||||
)
|
||||
|
||||
async def on_submit(self, interaction: discord.Interaction):
|
||||
view = Confirm()
|
||||
|
||||
await interaction.response.send_message(
|
||||
content=f"## Vorschau\n\n{self.content.value}",
|
||||
view=view,
|
||||
ephemeral=True,
|
||||
)
|
||||
|
||||
await view.wait()
|
||||
|
||||
if view.value:
|
||||
await interaction.user.send(f"Confirmed '{self.content.value}'")
|
||||
|
||||
|
||||
@discord.app_commands.command()
|
||||
async def post(interaction: discord.Interaction):
|
||||
await interaction.response.send_modal(PostModal())
|
||||
|
|
Loading…
Reference in a new issue