Scale up as you grow — whether you're running one virtual machine or ten thousand.

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.

This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Not recommended.
No command handler (all commands in the main file). No informations about intents (very important when the bot hit 100+ servers). Nothing about slash commands. So it’s not “How To Build a Discord Bot with Node.js” but “how to build a very useless basic discord bot with node.js”.
Don’t waste your time and take a look on YouTube.
Correct slash command link: https://discordjs.guide/interactions/slash-commands.html#registering-slash-commands
If you aren’t able to make the bot an administrator, then at least give it as many options possible under the “text permissions” column. When you follow the link to add the bot to the channel, make sure there is a green checkmark next to each of the items you selected. If you notice any denied permissions then your bot will not be able to do those activities. You may have to adjust your permissions on the server you are attempting to add the bot.
There are also new setting for a bot you may want to adjust in the https://discord.com/developers/applications/
Here is a new code snippt using discord.js v14
// Require the necessary discord.js classes
const { Client, Events, GatewayIntentBits } = require('discord.js');
const { token } = require('./config.json');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent
]
});
client.on("messageCreate", (message) => {
if (message.author.bot) return;
if (!message.content.startsWith(prefix)) return;
const commandBody = message.content.slice(prefix.length);
const args = commandBody.split(' ');
const command = args.shift().toLowerCase();
if (command === "ping") {
const timeTaken = Date.now() - message.createdTimestamp;
message.reply("Pong! This message had a latency of " + timeTaken.ms + ".");
}
else if (command === "sum") {
const numArgs = args.map(x => parseFloat(x));
const sum = numArgs.reduce((counter, x) => counter += x);
message.reply("The sum of all the arguments you provided is " + sum + "!");
}
});
If you want your script to always stay running on your server in the background, look into the forever npm package: https://www.npmjs.com/package/forever
Once you install it you can run your script: forever index.js
If you want to see what scripts are running you can use forever list
If you want forever to watch your file for changes and automatically reload it, you can run it with the -w hook:
forever -w index.js
This comment has been deleted
If you want to node script to run forever in the background, checkout the forever npm package: https://www.npmjs.com/package/forever
If you want forever to watch your file for changes and automatically reload, run it with the -w flag:
forever -w index.js