M
M
mlebedzeu2020-12-07 17:09:54
Node.js
mlebedzeu, 2020-12-07 17:09:54

Can't see get in bot.js, what should I do?

Here is the bot.js code:

const Discord = require('discord.js');
const bot = new Discord.Client();
bot.commands = new Discord.Collection();
const fs = require("fs");
let config = require('./botconfig.json');
let token = config.token
let prefix = config.prefix

fs.readdir('./cmds/',(err,files)=>{
    if(err) console.log(err);
    let jsfiles = files.filter(f => f.split(".").pop() === "js");
    if(jsfiles.length <=0) console.log("Нет команд для загрузки!");
    console.log(`Загружено ${jsfiles.length} команд`);
    jsfiles.forEach((f,i) =>{
        let props = require(`./cmds/${f}`);
        console.log(`${i+1}.${f} Загружен!`);
        bot.commands.set(props.help.name,props);
    })


bot.on('ready', () => {
  console.log(`Включився ${bot.user.username}`);
  bot.generateInvite(["ADMINISTRATOR"]).then(link =>{
      console.log(link);
  })
});

bot.on('message', async message => {
    if(message.author.bot) return;
    if(message.channel.type == "dm") return;
    let user = message.author.username;
    let userid = message.author.id;
    let messageArray = message.content.split(" ");
    let command =   messageArray[0].toLowerCase();
    let args = messageArray.slice(1);
    if(!message.content.startsWith(prefix)) return;
    let cmd = bot.command.get(command.slice(prefix.length));
    if(cmd) cmd.run(bot,message,args);
});

bot.login(token)});

here is the ping.js code:
const Discord = module.require("discord.js");
const fs = require("fs");
module.exports.run = async (bot,message,args) => {
    message.channel.send('pong!');
};
module.exports.help = {
    name: "ping"
};

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2020-12-07
@Alexandre888

https://discordjs.guide/additional-info/changes-in...

The ClientUserGuildSettings class has been removed entirely, along with all other user account-only properties and methods.

The ClientUserGuildSettings class has been completely removed, along with all other user account-only properties and methods.

in general, the code itself is very outdated, it was written on discord.js <= v11, so now it will not work properly - I advise you to just use the standard template for writing code:
const Discord = require('discord.js');
const client = new Discord.Client();

client.on('ready', () => {
  console.log(`${client.user.tag} запустился!`);
});

client.on('message', msg => {
  if (msg.content === 'ping') {
    msg.reply('Pong!');
  }
});

client.login('token');

it has a distinct advantage because you can work with multiple commands at once.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question