A
A
Anton Rosin2020-11-12 23:14:08
Node.js
Anton Rosin, 2020-11-12 23:14:08

The same Discord bot command on VPS does not work, although everything works on the computer (Discord.JS) How to solve?

Here is the code:

The code

const fs = require('fs');
const format = require('node.date-time');
const news = require('./news.json');
const cfg = {"token": "Токен бота", "prefix": "=","welcomehookid":"ID вебхука", "welcomehooktoken":"Токен вебхука",}
const token = cfg.token;
const prefix = cfg.prefix;
const Discord = require('discord.js');
const { stringify } = require('querystring');
const bot = new Discord.Client();
const welcomehook = new Discord.WebhookClient(cfg.welcomehookid, cfg.welcomehooktoken);
const newshook = new Discord.WebhookClient("ID вебхука", "Токен вебхука");
const newsForHook = news.newsToPublish;
const langMessages = {
  "russian": {
    "donthavekickperm": "У вас нет разрешения на кик пользователя.",
    "pleasementiontokick": "Пожалуйста, упомяните участника, которого хотите кикнуть.",
    "newspublished1": "Ок",
    "newspublished2": "новость из памяти бота успешно опубликована.",
    "news": "Новость из памяти бота:",
    "channelcleared1": "Успешно удалено сообщений:",
    "channelcleared2": "Успешно удалены все сообщения в канале.",
    "hi": "Привет",
    "hiHelloText": `добро пожаловать на наш сервер!`,
  },
  "serbian": {
    "donthavekickperm": "Немате дозволу да шутнете корисника.",
    "pleasementiontokick": "Молимо вас да наведете члана који желите да шутнете.",
    "newspublished1": "Dobro",
    "newspublished2": "вести из бот меморије успешно објављене.",
    "news": "Вести из бот меморије",
    "channelcleared1": "Успешно избрисане поруке:",
    "channelcleared2": "Успешно избрисане све поруке у каналу.",
    "hi": "Здраво",
    "hiHelloText": `добродошли на наш сервер!`
  },
  "english": {
    "donthavekickperm": "You don't have permission to kick the user",
    "pleasementiontokick": "Please mention the member you want to kick",
    "newspublished1": "Ok",
    "newspublished2": "news from bot\'s memory is successfully published/",
    "news": "News from bot\'s memory",
    "channelcleared1": "Successfully deleted messages:",
    "channelcleared2": "Successfully deleted all messages in the channel.",
    "hi": "Hi",
    "hiHelloText": `welcome to our server!`
  },
  "recent": {
  }
}
let logtext = "";


bot.on('ready', () => {
  logtext = `Logged in as ${bot.user.tag}`;
  console.log(logtext);
  log(logtext, "info");
  langMessages.recent = langMessages.english;
  bot.once('reconnecting', () => {
    console.log('Reconnecting!');
  });
  bot.once('disconnect', () => {
    console.log('Disconnect!');
  });
});

bot.on('guildMemberAdd', member => {
  welcomehook.send(`${langMessages.recent.hi} ${member.username}, ${langMessages.recent.hiHelloText}`);
  });
  
bot.on('message', msg => {
  logtext = `${msg.channel.name}(${msg.guild.name}) : ${msg.author.tag} : ${msg.content}`;
  console.log(`\n\n${logtext}`);
  log(logtext, "msg");
  
  
  if (!msg.guild || msg.author.bot || !msg.content.startsWith(prefix)) return;
  
  else msgHandler(msg);
});


bot.login(token).then(() => {
})


function msgHandler(msg) {
  
  let args = msg.content.split(' ');
  let commandarr = args[0].split(prefix)
  commandarr.splice(0, 1);
  let command = commandarr[0];
  args.splice(0, 1);
  console.log(command);
  console.log(args);

  if(msg.content.startsWith(prefix + "kick")){
    if(!msg.member.hasPermission("KICK_MEMBERS"))return(msg.reply(langMessages.recent.donthavekickperm))
    let tokick = msg.mentions.members.first()
    if(!tokick)return(msg.reply(langMessages.recent.pleasementiontokick))
    let reason = "testing bot commands";
    msg.delete();
    tokick.kick(reason);
  }
  
  else if (command == "hi") {
    msg.channel.send(`${langMessages.recent.hi}, ${msg.author.username}`);
  }

  else if (command == "publishnews") {
    newshook.send(newsForHook);
    msg.channel.send(`${langMessages.recent.newspublished1} ${msg.author.username}, ${langMessages.recent.newspublished2}`);
    msg.channel.send(`${langMessages.recent.news}: ${newsForHook}`);
  }
  
  else if (command == "clear") {
    msg.channel.bulkDelete(100);
    msg.channel.send(`${langMessages.recent.channelcleared2}`).then((message) => {
      message.channel.bulkDelete(1);
    });
  }
    
  else if (command == "lang" && (args[0] == "russian" || "serbian" || "english")) {
    switch (args[0]) {
      case "russian":
        translate("Russian");
        msg.channel.send("Bot translated to Russian")        
        break;
      case "serbian":
        translate("Serbian");
        msg.channel.send("Bot translated to Serbian")        
        break;
      case "english":
        translate("English");
        msg.channel.send("Bot translated to English")        
        break;
    }
  }};

function translate(lang) {
  switch (lang) {
    case "Russian":
      langObj = langMessages.russian;
      break
    case "Serbian":
      langObj = langMessages.serbian;
      break
    case "English":
      langObj = langMessages.english;
      break
  };
  langMessages.recent = langObj;
  logtext = `Bot translated to ${lang}`
  console.log(logtext)
  log(logtext, "info")
};
    
function log(logText, logType) {
  function logTime(){
    return new Date().format('Y-MM-dd HH:mm:SS');
  };
  let logPrefix = "";
  switch (logType){
    case "msg":
      logPrefix = "[MESSAGE]";
      break;
      
    case "info":
      logPrefix = "[INFO]";
    break;
  }
  logPrefix += " ";
  let logResult = `(${bot.user.tag}): ${logTime()} ${logPrefix} ${logText}`
  
  fs.appendFile(`recent.log`, `${logResult}\n`, () =>{
  });
};


I have this code both on my computer (everything works on it) and on the VPS (only the clear bot command does not work there (this command deletes all messages in the text channel))

On the VPS, when using the clear bot command, it gives the following error:
Error text

(node:50691) UnhandledPromiseRejectionWarning: TypeError: Object.entries(...).filter(...).flatMap is not a function
at new APIRequest (/root/golubovicbot/node_modules/discord.js/src/rest/APIRequest.js:24:10)
at RESTManager.request (/root/golubovicbot/node_modules/discord.js/src/rest/RESTManager.js:39:24)
at Proxy.options (/root/golubovicbot/node_modules/discord.js/src/rest/APIRouter.js:30:19)
at MessageManager._fetchMany (/root/golubovicbot/node_modules/discord.js/src/managers/MessageManager.js:140:75)
at MessageManager.fetch (/root/golubovicbot/node_modules/discord.js/src/managers/MessageManager.js:68:86)
at TextChannel.bulkDelete (/root/golubovicbot/node_modules/discord.js/src/structures/interfaces/TextBasedChannel.js:358:40)
at msgHandler (/root/golubovicbot/bot.js:134:17)
at Client.bot.on.msg (/root/golubovicbot/bot.js:83:8)
at Client.emit (events.js:198:13)
at MessageCreateAction.handle (/root/golubovicbot/node_modules/discord.js/src/client/actions/MessageCreate.js:31:14)
(node:50691) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:50691) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.


If there are any errors in the code, please point them out to me so that I don't repeat them again :)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Yuriev, 2020-11-12
@Rosin886

You have node version 10 or lower on the server. Update.
Array.prototype.flatMap() appeared in Node.js v11.0.0

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question