S
S
superboyvasek2020-03-02 15:28:35
Vue.js
superboyvasek, 2020-03-02 15:28:35

Why does the bot not accept commands?

bot discord

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

fs.readdir('./cmds', (err, files) =>{
  if (err) console.log(err);
  let jsfile = files.filter(f => f.split('.').pop() === 'js');
  if (jsfile.length <= 0) return console.log('Комманды не найдены!');
  console.log(`Loaded ${jsfile.length} commands`);
  jsfile.forEach((f, i) => {
    let props = require(`./cmds/${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 uid = message.author.id;
  if(!profile[uid]){
    profile[uid] ={
      coins:10,
      warns:0,
      xp:0,
      lvl:0,
    };
  };
  let u = profile[uid];
  u.coins +=0.25;
  u.xp +=0.35;
  if(u.xp>= (u.lvl * 5)){
    u.xp = 0;
    u.lvl += 1;
  }
  fs.writeFile('./profile.json',JSON.stringify(profile),(err)=>{
    if(err) console.log(err);
  });
  let user = message.author.username;
  let userid = message.author.id;
  let messageArray = message.cotent.split(" ");
  let command = messageArray [0].toLowerCase();
  let args = messageArray.slice(1);
  if(!message.content.startsWith(prefix)) return;
  let cmd = bot.commands.get(command.slice(prefix.length));
  if(cmd) cmd.run(bot,message,args);
});

bot.login(token);
the bot code itself why the bot does not read messages find my mistake

Answer the question

In order to leave comments, you need to log in

2 answer(s)
0
0xD34F, 2019-07-16
@vessels

methods: {
  submit() {
    ...

G
gohellp, 2020-09-06
@gohellp

I can say that I did not see the message check.
for example:
You have:

if(!profile[uid]){
    profile[uid] ={
      coins:10,
      warns:0,
      xp:0,
      lvl:0,
    };

So that there is at least a small check:
if(message.content.toLowerCase()==="!profile[uid]"){
    profile[uid] ={
      coins:10,
      warns:0,
      xp:0,
      lvl:0,
    };

I advise you to still look through a lot of other codes and, nevertheless, open and read the documentation well. Otherwise, you will continue to make such stupid mistakes.
About the code I wrote: the bot will respond to !profile[uid] and nothing more. In order for it to pull out the mention of someone, you need to write this:
if(message.content.toLowerCase()==="!profile"){
let mbr = message.mentions.members.first() || message.member;
};

And then a question for you: Did you write the code without studying any documentation?
Just for the bot to write this:
profile[uid] ={
coins:10,
warns:0,
xp:0,
lvl:0,
you need to at least tell him "write" and then he will write this to everyone. In order for each user to have their own values, a database is already needed.
I hope you read the documentation in the future and write your code perfectly.
PS: toLowerCase() makes from "CAPS" this: "caps" and so it is more convenient for users to interact with the bot. Everyone had a situation when you press capslock and forget about it;)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question