-
SurveyJS
Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App. With SurveyJS form UI libraries, you can build and style forms in a fully-integrated drag & drop form builder, render them in your JS app, and store form submission data in any backend, inc. PHP, ASP.NET Core, and Node.js.
This file will be put in the modules/ folder, and called as soon as the bot is launched with the Ready event (events/ready.js). I took it from this GitHub repository made by Androz. It allows you to easily synchronize and update your list of commands.
/** @document : app.js @author : Thomas Bnt @version : 3.0.0 @copyright : 2023, Thomas Bnt @license : GNU General Public License v3.0 @repository : https://github.com/thomasbnt/Bord-Pi @description: Un robot Discord gérant et aidant les utilisateurs pour un serveur. */ const fs = require('fs') const { Client, Collection, GatewayIntentBits, Options } = require('discord.js') const client = new Client({ // The intents will depend on what you want to do with the robot, // but don't forget to activate them in your discord.dev dashboard // at the address https://discord.com/developers/applications/{ID}/bot, // section "Privileged Gateway Intents" intents: [ GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages ], }) // We create a collection for commands client.commands = new Collection() const commandFiles = fs .readdirSync('./commands') .filter((file) => file.endsWith('.js')) for (const file of commandFiles) { const command = require(`./commands/${file}`) client.commands.set(command.data.name, command) } // Events like ready.js (when the robot turns on), // or messageCreate.js (when a user/robot sends a message) const eventFiles = fs .readdirSync('./events') .filter((file) => file.endsWith('.js')) for (const file of eventFiles) { const event = require(`./events/${file}`) if (event.once) { client.once(event.name, (...args) => event.execute(...args, client)) } else { client.on(event.name, (...args) => event.execute(...args, client)) } } // The interactionCreate event directly here, as this is the heart of the robot. client.on('interactionCreate', async (interaction) => { if (!interaction.isCommand()) return const command = client.commands.get(interaction.commandName) if (!command) return // We log when a user makes a command try { await console.log( `/${interaction.commandName} — Par ${interaction.user.username}` ) await command.execute(interaction, client) // But if there is a mistake, // then we log that and send an error message only to the person (ephemeral: true) } catch (error) { console.error(error) return interaction.reply({ content: "An error occurred while executing this command!", ephemeral: true, fetchReply: true }) } }) // The token of your robot to be inserted client.login("NICE TOKEN NEVER TO BE DISCLOSED")
Install the latest stable version of Node.js
Related posts
-
Building Your First Browser Game with Three.js and React: Part 1 - Getting Started
-
WebSockets com Socket.io: Criando Aplicações Real-Time com Node.js
-
Day 2: Setting Up Angular Development Environment
-
Part 2: Setting Up Your Node.js Environment
-
Announcing Node.js 22.0.0: What’s New and Why It Matters