ForgeScript is a comprehensive package that empowers you to effortlessly interact with Discord's API. It ensures scripting remains easy to learn and consistently effective.
npm install forgescriptbash
npm i https://github.com/tryforge/ForgeScript.git
`
> If installing this repository instead of npm, you must have TypeScript as dependency (npm i typescript --save-dev)
file:
`js
const { ForgeClient } = require("forgescript")
const client = new ForgeClient({
intents: [
"GuildMessages",
"Guilds",
"MessageContent" // This intent is privileged, must be whitelisted in dev portal, in your application.
],
events: [
"messageCreate",
"ready"
], // Events our bot will act on
prefixes: [
"!",
"?"
] // The prefixes to use for our bot!
})
client.login("token")
`
This will be enough to put our bot on.
$3
Registering commands is the way to go when we want something to happen on certain events.
#### Basic registering
Let's write this after our client initialization code:
`js
client.commands.add({
name: "user", // Not defining this creates a command that will be executed for every event fired of given type
code: Your name is $username!,
type: "messageCreate" // The event to act on
})
`
And this will register a command with name user that will return the name of the user that executed this command.
#### Registering from a root folder
The previous way to register commands can fill our index file with a lot of junk code, so there's a way to put files with commands in folders and load them from the index file.
1. Create a folder, with any name, and a file inside it, name it whatever you want (must end with .js) and write the following in it:
`js
module.exports = {
name: "user",
type: "messageCreate",
code: Your name is $username!
}
`
This is essentially the same as the previous command, but will be loaded from a folder!
2. Now, let's go back to our index file and write the following after client initialization (Make sure you've erased the code to register a command from index file):
`js
client.commands.load("./")
`
Replace