![Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility](https://cdn.sanity.io/images/cgdhsj6q/production/97774ea8c88cc8f4bed2766c31994ebc38116948-1664x1366.png?w=400&fit=max&auto=format)
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
A library provides declarative UI for discord.py.
Python3.10 or higher is required
discord.py^2.2.0 is required; any compatibility under 2.1.x or 1.x is not guaranteed
Using the latest stable release of discord.py is recommended
pip install ductile-ui
You can define component as return value of View.render()
.
To store state, use State
.
# This example requires the 'message_content' privileged intent to function.
import random
import discord
from discord.ext import commands
from ductile import State, View, ViewObject
from ductile.controller import MessageableController
from ductile.ui import Button
class Bot(commands.Bot):
def __init__(self) -> None:
super().__init__(command_prefix="!", intents=discord.Intents.all())
async def on_ready(self) -> None:
print(f"Logged in as {self.user}")
print("Ready!")
class CounterView(View):
def __init__(self) -> None:
super().__init__()
self.count = State(0, self)
def render(self) -> ViewObject:
e = discord.Embed(title="Counter", description=f"Count: {self.count.get_state()}")
async def handle_increment(interaction: discord.Interaction) -> None:
await interaction.response.defer()
self.count.set_state(lambda x: x + 1)
async def handle_decrement(interaction: discord.Interaction) -> None:
await interaction.response.defer()
self.count.set_state(lambda x: x - 1)
async def stop(interaction: discord.Interaction) -> None:
await interaction.response.defer()
self.stop()
# Define UI using ViewObject
return ViewObject(
embeds=[e],
components=[
Button("+1", style={"color": "blurple", "row": 0}, on_click=handle_increment),
Button("-1", style={"color": "blurple", "row": 0}, on_click=handle_decrement),
Button(
"random",
style={"color": "green", "row": 1},
# if you passed synchronous function to Button.on_click,
# library automatically calls `await interaction.response.defer()`.
on_click=lambda _: self.count.set_state(random.randint(0, 100)),
),
Button("stop", style={"color": "red", "row": 1}, on_click=stop),
],
)
bot = Bot()
@bot.command(name="counter")
async def send_counter(ctx: commands.Context) -> None:
controller = MessageableController(CounterView(), messageable=ctx.channel)
await controller.send()
timed_out, states = await controller.wait()
await ctx.send(f"Timed out: {timed_out}\nCount: {states['count']}")
bot.run("MY_COOL_BOT_TOKEN")
FAQs
A library provides declarative ui for discord.py
We found that ductile-ui demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.