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
|
// 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
|
// README at: https://github.com/devcontainers/templates/tree/main/src/python
|
||||||
{
|
{
|
||||||
"name": "Python 3",
|
"name": "LEVbot",
|
||||||
"build": {
|
"build": {
|
||||||
"dockerfile": "Dockerfile",
|
"dockerfile": "Dockerfile",
|
||||||
"context": "..",
|
"context": "..",
|
||||||
|
|
|
@ -1,27 +1,30 @@
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
from discord.ext.commands import Bot
|
|
||||||
|
|
||||||
from .commands import foo, ping
|
from .commands import post
|
||||||
|
|
||||||
_logger = logging.getLogger(__name__)
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class LenaverseBot(Bot):
|
class LenaverseBot(discord.Client):
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
intents = discord.Intents.default()
|
intents = discord.Intents.default()
|
||||||
intents.message_content = True
|
intents.message_content = True
|
||||||
|
|
||||||
super().__init__(
|
super().__init__(intents=intents)
|
||||||
command_prefix="!",
|
|
||||||
intents=intents,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.add_command(ping)
|
self.tree = discord.app_commands.CommandTree(self)
|
||||||
self.add_command(foo)
|
self.tree.add_command(post)
|
||||||
|
|
||||||
|
async def setup_hook(self):
|
||||||
|
await self.tree.sync()
|
||||||
|
_logger.info("Commands synced")
|
||||||
|
|
||||||
async def on_ready(self) -> None:
|
async def on_ready(self) -> None:
|
||||||
_logger.info(self.guilds)
|
_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!")
|
_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()
|
# Define a simple View that gives us a confirmation menu
|
||||||
async def ping(ctx: commands.Context):
|
class Confirm(ui.View):
|
||||||
await ctx.send("pong")
|
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()
|
class PostModal(ui.Modal, title="foobar2000"):
|
||||||
async def foo(ctx: commands.Context, arg: str):
|
content = ui.TextInput(
|
||||||
await ctx.send(arg)
|
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