fix: examples

This commit is contained in:
Yuzu 2022-07-14 12:54:33 -05:00
parent fa604fd164
commit a2dd9ddf5d
6 changed files with 21 additions and 103 deletions

View File

@ -3,11 +3,10 @@ import {
ActionRowBuilder,
ButtonBuilder,
ButtonStyles,
ComponentInteraction,
GatewayIntents,
InteractionResponseTypes,
Session,
} from 'https://x.nest.land/biscuit@0.1.0/mod.ts';
} from 'https://x.nest.land/biscuit/mod.ts';
const token = Deno.env.get("TOKEN") ?? Deno.args[0];
@ -36,22 +35,22 @@ session.on("messageCreate", (message) => {
console.log(args, name);
if (name === 'ping') {
message.reply({ components: [row] })
.then(() => {})
.catch((e) => console.error(e));
message.reply({ components: [row] });
}
});
// Follow interaction event
session.on('interactionCreate', (interaction) => {
if (!interaction.isComponent()) return;
const component = interaction as ComponentInteraction;
if (component.customId == "ping") {
component.respond({
if (!interaction.isComponent()) {
return;
}
if (interaction.customId === "ping") {
interaction.respond({
type: InteractionResponseTypes.ChannelMessageWithSource,
data: { content: "pong!" },
});
}
});
await session.start();
session.start();

View File

@ -3,7 +3,8 @@
* this example should work on most systems, but if it doesn't just clone the library and import everything from mod.ts
*/
import { GatewayIntents, Session } from "@oasisjs/biscuit";
const { GatewayIntents, Session } = require("@oasisjs/biscuit");
// if it didn't worked use:
// const { GatewayIntents, Session } = require("@oasisjs/biscuit");
@ -16,15 +17,17 @@ session.on("ready", (payload) => {
});
session.on("messageCreate", async (message) => {
// GET
if (message.content.startsWith("whatever")) {
const whatever = await message.fetch().then(console.log);
const whatever = await message.fetch();
console.log(whatever);
}
// POST
if (message.content.startsWith("ping")) {
message.reply({ content: "pong!" }).catch((err) => console.error(err));
}
});
await session.start();

View File

@ -1,11 +1,11 @@
/**
* Deno example
*/
*/
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";
// Session to create a new bot (and intents)
import { GatewayIntents, Session } from "https://x.nest.land/biscuit/mod.ts";
const token = Deno.env.get("TOKEN") ?? Deno.args[0];
@ -35,5 +35,5 @@ session.on("messageCreate", (message) => {
}
});
await session.start();
session.start();

View File

@ -1,42 +0,0 @@
/**
* Biscuit node example
*/
/** @type {NodeJS.Process} process */
const process = require("node:process");
const { Session, GatewayIntents } = require("@oasisjs/biscuit");
/** @type {string} token */
const token = process.env.TOKEN || "YOUR_TOKEN_HERE";
if (token === "") {
return new Error("Please set the TOKEN environment variable");
}
const intents = GatewayIntents.MessageContent | GatewayIntents.Guilds | GatewayIntents.GuildMessages;
const session = new Session({ token, intents });
const PREFIX = ">";
session.on("ready", (data) => {
console.log("Ready! Let's start chatting!");
console.log("Connected as: " + data.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();
if (name === "ping") {
message.reply({ content: "pong!" });
}
});
try {
session.start();
} catch(err){
throw err;
}

View File

@ -1,42 +0,0 @@
/**
* Biscuit node example
*/
/** @type {NodeJS.Process} process */
import process from 'node:process';
import { Session, GatewayIntents } from '@oasisjs/biscuit';
/** @type {string} token */
const token = process.env.TOKEN || "YOUR_TOKEN_HERE";
if (token === "") {
console.log(new Error("Please set the TOKEN environment variable"));
}
const intents = GatewayIntents.MessageContent | GatewayIntents.Guilds | GatewayIntents.GuildMessages;
const session = new Session({ token, intents });
const PREFIX = ">";
session.on("ready", (data) => {
console.log("Ready! Let's start chatting!");
console.log("Connected as: " + data.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();
if (name === "ping") {
message.reply({ content: "pong!" });
}
});
try {
session.start();
} catch(err){
throw err;
}

View File

@ -1,5 +1,5 @@
import "https://deno.land/std@0.146.0/dotenv/load.ts";
import { CreateApplicationCommand, GatewayIntents, InteractionResponseTypes, Session } from "./deps.ts";
import { CreateApplicationCommand, GatewayIntents, InteractionResponseTypes, Session } from "https://x.nest.land/biscuit/mod.ts";
const token = Deno.env.get("TOKEN") ?? Deno.args[0];