mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-03 05:26:07 +00:00
Add node example
This commit is contained in:
parent
cefb35a622
commit
79156d092c
42
examples/node.js
Normal file
42
examples/node.js
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user