添加kick player命令后,此代码出现问题。机器人的其余部分不起作用,该命令也不起作用

时间:2020-08-30 14:41:48

标签: javascript discord discord.js

const { Client, RichEmbed } = require("discord.js");
    const chalk = require("chalk");

    const { token, prefix } = require("../config/config.js");

    const client = new Client();

    client.on("ready", () => {
      console.log(chalk.red("Witamy w konsoli bota Island"));
      console.log(chalk.green(`Zalogowano jako ${client.user.tag}!`));
    });
    client.on("message", (msg) => {
      const { author, guild } = msg;

      if (author.bot || !guild) {
        return;
      }

      if (msg.content === "-info") {
        msg.channel.send("Witam, jestem botem stworzonym przez Rewera");
      }
    });
    client.on("message", (msg) => {
      const { author, guild } = msg;

      if (author.bot || !guild) {
        return;
      }

      if (msg.content === "-komendy") {
        msg.channel.send("Już wkrótce, zostaną dodane. Są w trakcie tworzenia");
      }
      if (msg.content === "-wersja") {
        msg.channel.send("Wersja: ALPHA 0.04");
      }
      if (msg === "-tworca") {
        const botAuthor = "Rewer";
        const botVersion = "v1.1";
        msg.channel.send(
          "Autorem bota jest: **${botAuthor}**! Wersja *${botVersion}*. "
        );
      }
      if (message.content.startsWith("$kick")) {

        if (!message.member.roles.find("name", "Admin"))
            return;
        // Easy way to get member object though mentions.
        var member = message.mentions.members.first();
        // Kick
        member.kick().then((member) => {
            // Successmessage
            message.channel.send(":wave: " + member.displayName + " has been successfully kicked :point_right: ");
        }).catch(() => {
            // Failmessage
            message.channel.send("Access Denied");
        });
    }
    });
    // Error handler
    client.on("debug", () => {});
    client.on("warn", () => {});
    client.on("error", () => {});
    client.login(token);

添加了kick player命令后,此代码有问题。该机器人的其余部分无法正常工作,该命令也不会

我不知道该如何删除踢票代码。该机器人神奇地开始工作。

任何人都对如何解决它有任何想法,我是初学者,所以请理解

1 个答案:

答案 0 :(得分:0)

处理消息事件时,将“ msg”作为参数传递

client.on("message", (msg) => {

所以您应该在整个过程中使用“ msg”

不过,在踢踢命令中,您开始使用“消息”

if (message.content.startsWith("$kick")) {if (!message.member.roles.find("name", "Admin"))

您必须将“ message”更改为“ msg ”,以匹配您在开始时为变量指定的名称 client.on(“ message”,( msg )=> {