mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-04 05:56:09 +00:00
feat(examples): SlashCommand & Builders
This commit is contained in:
parent
c4af965d13
commit
9c6551c1bd
1
examples/.env.example
Normal file
1
examples/.env.example
Normal file
@ -0,0 +1 @@
|
|||||||
|
TOKEN=YOUR_BOT_TOKEN
|
58
examples/builderComponent.ts
Normal file
58
examples/builderComponent.ts
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
import "https://deno.land/std@0.146.0/dotenv/load.ts";
|
||||||
|
import {
|
||||||
|
ActionRowBuilder,
|
||||||
|
ButtonBuilder,
|
||||||
|
ButtonStyles,
|
||||||
|
ComponentInteraction,
|
||||||
|
GatewayIntents,
|
||||||
|
InteractionResponseTypes,
|
||||||
|
Session,
|
||||||
|
} from "./deps.ts";
|
||||||
|
|
||||||
|
const token = Deno.env.get("TOKEN") ?? Deno.args[0];
|
||||||
|
|
||||||
|
if (!token) {
|
||||||
|
throw new Error("Please provide a token");
|
||||||
|
}
|
||||||
|
|
||||||
|
const intents = GatewayIntents.MessageContent | GatewayIntents.Guilds | GatewayIntents.GuildMessages;
|
||||||
|
const session = new Session({ token, intents });
|
||||||
|
|
||||||
|
const PREFIX = ">";
|
||||||
|
const components = new ButtonBuilder().setCustomId("ping").setLabel("Hello!").setStyle(ButtonStyles.Success);
|
||||||
|
const row = new ActionRowBuilder<ButtonBuilder>().addComponents(components).toJSON();
|
||||||
|
|
||||||
|
session.on("ready", (payload) => {
|
||||||
|
console.log("Logged in as:", payload.user.username);
|
||||||
|
});
|
||||||
|
|
||||||
|
session.on("messageCreate", (message) => {
|
||||||
|
if (message.author?.bot || !message.content.startsWith(PREFIX)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const args = message.content.substring(PREFIX.length).trim().split(/\s+/gm);
|
||||||
|
const name = args.shift()?.toLowerCase();
|
||||||
|
console.log(args, name);
|
||||||
|
|
||||||
|
if (name === "ping") {
|
||||||
|
console.log(row)
|
||||||
|
message.reply({ components: [row] })
|
||||||
|
.then(() => {})
|
||||||
|
.catch(e => console.error(e))
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Follow interaction event
|
||||||
|
session.on("interactionCreate", (interaction) => {
|
||||||
|
if (!interaction.isComponent()) return;
|
||||||
|
const component = interaction as ComponentInteraction;
|
||||||
|
if (component.customId == "ping") {
|
||||||
|
component.respond({
|
||||||
|
type: InteractionResponseTypes.ChannelMessageWithSource,
|
||||||
|
data: { content: "pong!" },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
await session.start();
|
43
examples/slashCommand.ts
Normal file
43
examples/slashCommand.ts
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
import "https://deno.land/std@0.146.0/dotenv/load.ts";
|
||||||
|
import { CreateApplicationCommand, GatewayIntents, InteractionResponseTypes, Session } from "./deps.ts";
|
||||||
|
|
||||||
|
const token = Deno.env.get("TOKEN") ?? Deno.args[0];
|
||||||
|
|
||||||
|
if (!token) {
|
||||||
|
throw new Error("Please provide a token");
|
||||||
|
}
|
||||||
|
|
||||||
|
const intents = GatewayIntents.MessageContent | GatewayIntents.Guilds | GatewayIntents.GuildMessages;
|
||||||
|
const session = new Session({ token, intents });
|
||||||
|
|
||||||
|
const command: CreateApplicationCommand = {
|
||||||
|
name: "ping",
|
||||||
|
description: "Replies with pong!",
|
||||||
|
};
|
||||||
|
|
||||||
|
const guildId = '';
|
||||||
|
|
||||||
|
session.on("ready", async (payload) => {
|
||||||
|
console.log("Logged in as:", payload.user.username);
|
||||||
|
console.log("Creating the application commands...");
|
||||||
|
// create command
|
||||||
|
try {
|
||||||
|
await session.createApplicationCommand(command, guildId);
|
||||||
|
console.log("Done!");
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Follow interaction event
|
||||||
|
session.on("interactionCreate", (interaction) => {
|
||||||
|
if (!interaction.isCommand()) return;
|
||||||
|
if (interaction.commandName === "ping") {
|
||||||
|
interaction.respond({
|
||||||
|
type: InteractionResponseTypes.ChannelMessageWithSource,
|
||||||
|
data: { content: "pong!" },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
await session.start()
|
Loading…
x
Reference in New Issue
Block a user