I have done discord.js bot recently, but it does not respond to commands, like !greeting. Here is a code of index.js
const { Client, GatewayIntentBits } = require('discord.js');
const robot = new Client
({ intents: [ GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages ] });
const comms = require("./comms.js");
const fs = require('fs');
let config = require('./config.json');
let prefix = config.prefix;
let token = config.token;
robot.on("ready", function() {
console.log(robot.user.username + " пробудився, і готовий ділитися мудрістю...");
});
robot.on('message', (msg) => {
if (msg.author.username != robot.user.username && msg.author.discriminator != robot.user.discriminator) {
var comm = msg.content.trim() + " ";
var comm_name = comm.slice(0, comm.indexOf(" "));
var messArr = comm.split(" ");
for (comm_count in comms.comms) {
var comm2 = prefix + comms.comms[comm_count].name;
if (comm2 == comm_name) {
comms.comms[comm_count].out(robot, msg, messArr);
}
}
}
});
robot.login(token);
And here is comms.js
const Discord = require('discord.js');
let config = require('./config.json');
let prefix = config.prefix;
function test(robot, mess, args) {
mess.channel.send('Test!')
}
function greeting(robot, mess, args) {
mess.reply("Вітаю тебе! Почуй мою мудрість, і ставатимеш як я...")
}
var comms_list = [
{
name: "test",
out: test,
about: "Тестова команда"
}];
comms_list.push({
name: "greeting",
out: greeting,
about: "Команда для вітання"
});
module.exports.comms = comms_list;
What I should to do??? I with my friend sit on it for three days. Looking forward to hearing from you!