Почему мой дискорд-бот не выходит в интернет без ошибок или чего-либо еще? - PullRequest
1 голос
/ 10 июля 2019

Так что, в принципе, я пытался решить эту проблему часами, но безуспешно.Вот что происходит, когда я пытаюсь запустить бота:

https://gyazo.com/3a941b4372c88be07c76c5b004327f71

Я проверил, что главное правильно и что все правильно, как файлы json и фактический код.

bot.js ->

const botconfig = require("./botconfig.json");
const Discord = require("discord.js");

const bot = new Discord.Client({disableEveryone: true});

bot.on("ready", async () => {
  console.log(`${bot.user.username} is online!`);

  bot.user.setActivity("Tickets", {type: "WATCHING"});

});

bot.on('message', async message => {
  if(message.author.bot) return;
  if(message.channel.type === "dm") return;

  let prefix = botconfig.prefix;
  let messageArray = message.content.split(" ");
  let cmd = messageArray[0];
  let args = messageArray.slice(1);

  if(cmd === `${prefix}new`){

  let embed = new Discord.RichEmbed()
  .setTitle("Ticket created")
  .setDescription("Ticket #ticket- has been created successfully.")
  .setColor("#15f153")
  .setFooter("chefren#9582 | 2019")


    return message.channel.send(embed);

}


    if(cmd === `${prefix}ticketcreation`){

    let embed = new Discord.RichEmbed()
    .setTitle("Ticket")
    .setDescription("Do you require help or support? React with :white_check_mark: ")
    .setColor("#15f153")
    .setFooter("dl121#9582 | 2019")

      msg = await message.channel.send(embed);

      await msg.react('✅')

      message.awaitReactions(filter, { max: 1, time: 60000, errors: ['time'] })
    .then(collected => {
        const reaction = collected.first();

        if (reaction.emoji.name === '✅') {
            message.reply('you reacted with a thumbs up.');
        }


});

bot.login(botconfig.token);
    }
  })



Package.json

{
  "name": "bot",
  "version": "1.0.0",
  "description": "A bot",
  "main": "bot.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "andrew",
  "license": "ISC",
  "dependencies": {
    "cjs": "0.0.11",
    "discord.js": "^11.5.1",
    "fs": "0.0.1-security",
    "node.js": "0.0.0"
  },
  "devDependencies": {}
}



До этого я исправлял это сообщение об ошибке:

Error: Cannot find module 'C:\Users\Andrew\Desktop\Discord Bots\Bot\bot,js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Function.Module.runMain (internal/modules/cjs/loader.js:829:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)

1 Ответ

0 голосов
/ 10 июля 2019

Судя по предоставленному вами коду, похоже, что есть проблемы с вашими фигурными скобками.Вызов bot.login({...}) фактически находился внутри обработчика bot.on('message'.Очевидно, что вы не будете получать сообщения без первого входа в систему, так что, вероятно, это и происходит.

Я заново сделал отступ в вашем коде и добавил необходимые фигурные скобки и скобки, чтобы в конце был выполнен вызов bot.loginсценария, вне каких-либо функций-обработчиков.

const botconfig = require("./botconfig.json");
const Discord = require("discord.js");

const bot = new Discord.Client({disableEveryone: true});

bot.on("ready", async () => {
  console.log(`${bot.user.username} is online!`);

  bot.user.setActivity("Tickets", {type: "WATCHING"});

});

bot.on('message', async message => {
  if(message.author.bot) return;
  if(message.channel.type === "dm") return;

  let prefix = botconfig.prefix;
  let messageArray = message.content.split(" ");
  let cmd = messageArray[0];
  let args = messageArray.slice(1);

  if (cmd === `${prefix}new`) {

    let embed = new Discord.RichEmbed()
    .setTitle("Ticket created")
    .setDescription("Ticket #ticket- has been created successfully.")
    .setColor("#15f153")
    .setFooter("chefren#9582 | 2019")

    return message.channel.send(embed);

  }


  if (cmd === `${prefix}ticketcreation`) {

    let embed = new Discord.RichEmbed()
    .setTitle("Ticket")
    .setDescription("Do you require help or support? React with :white_check_mark: ")
    .setColor("#15f153")
    .setFooter("dl121#9582 | 2019")

    let msg = await message.channel.send(embed);

    await msg.react('✅')

    message.awaitReactions(filter, { max: 1, time: 60000, errors: ['time'] })'
    .then(collected => {
      const reaction = collected.first();

      if (reaction.emoji.name === '✅') {
        message.reply('you reacted with a thumbs up.');
      }
    });
  }
});

// *** CHANGES WERE MADE ABOVE HERE ***

bot.login(botconfig.token);
...