Update examples

This commit is contained in:
Nicolás Serna 2022-07-14 14:14:18 -03:00
parent af73561279
commit 9193346f52
6 changed files with 183 additions and 180 deletions

View File

@ -1,4 +1,4 @@
import "https://deno.land/std@0.146.0/dotenv/load.ts";
import 'https://deno.land/std@0.146.0/dotenv/load.ts';
import {
ActionRowBuilder,
ButtonBuilder,
@ -7,23 +7,23 @@ import {
GatewayIntents,
InteractionResponseTypes,
Session,
} from "./deps.ts";
} from 'https://x.nest.land/biscuit@0.1.0/mod.ts';
const token = Deno.env.get("TOKEN") ?? Deno.args[0];
if (!token) {
throw new Error("Please provide a 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 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('ready', (payload) => {
console.log('Logged in as:', payload.user.username);
});
session.on("messageCreate", (message) => {
@ -35,7 +35,7 @@ session.on("messageCreate", (message) => {
const name = args.shift()?.toLowerCase();
console.log(args, name);
if (name === "ping") {
if (name === 'ping') {
message.reply({ components: [row] })
.then(() => {})
.catch((e) => console.error(e));
@ -43,7 +43,7 @@ session.on("messageCreate", (message) => {
});
// Follow interaction event
session.on("interactionCreate", (interaction) => {
session.on('interactionCreate', (interaction) => {
if (!interaction.isComponent()) return;
const component = interaction as ComponentInteraction;
if (component.customId == "ping") {

View File

@ -11,11 +11,6 @@ const token = process.env.TOKEN;
const intents = GatewayIntents.MessageContent | GatewayIntents.Guilds | GatewayIntents.GuildMessages;
const session = new Session({ token, intents });
// uncomment to debug stuff
// session.on("debug", (any) => {
// console.debug(any);
// })
session.on("ready", (payload) => {
console.log("Logged in as:", payload.user.username);
});
@ -32,3 +27,4 @@ session.on("messageCreate", async (message) => {
});
await session.start();

View File

@ -3,6 +3,8 @@
*/
import "https://deno.land/std@0.146.0/dotenv/load.ts";
// Session for create a new bot and intents
import { GatewayIntents, Session } from "https://x.nest.land/biscuit@0.1.0/mod.ts";
const token = Deno.env.get("TOKEN") ?? Deno.args[0];
@ -34,3 +36,4 @@ session.on("messageCreate", (message) => {
});
await session.start();

View File

@ -2,10 +2,14 @@
* Biscuit node example
*/
// process for get the token
/** @type {NodeJS.Process} process */
import process from 'node:process';
// Session for create a new bot and intents
import { Session, GatewayIntents } from '@oasisjs/biscuit';
// Discord bot token
/** @type {string} token */
const token = process.env.TOKEN || "YOUR_TOKEN_HERE";
@ -15,6 +19,8 @@ if (token === "") {
const intents = GatewayIntents.MessageContent | GatewayIntents.Guilds | GatewayIntents.GuildMessages;
const session = new Session({ token, intents });
// Command prefix
const PREFIX = ">";
session.on("ready", (data) => {
@ -35,8 +41,4 @@ session.on("messageCreate", (message) => {
}
});
try {
session.start();
} catch(err){
throw err;
}

View File

@ -2,10 +2,14 @@
* Biscuit node example
*/
// process for get the token
/** @type {NodeJS.Process} process */
const process = require("node:process");
// Session for create a new bot and intents
const { Session, GatewayIntents } = require("@oasisjs/biscuit");
// Discord bot token
/** @type {string} token */
const token = process.env.TOKEN || "YOUR_TOKEN_HERE";
@ -15,6 +19,8 @@ if (token === "") {
const intents = GatewayIntents.MessageContent | GatewayIntents.Guilds | GatewayIntents.GuildMessages;
const session = new Session({ token, intents });
// Command prefix
const PREFIX = ">";
session.on("ready", (data) => {
@ -35,8 +41,4 @@ session.on("messageCreate", (message) => {
}
});
try {
session.start();
} catch(err){
throw err;
}