【问题标题】:ERR_INVALID_ARG_TYPE on Discord.jsDiscord.js 上的 ERR_INVALID_ARG_TYPE
【发布时间】:2022-01-05 21:38:18
【问题描述】:

所以我在 Discord.js 中制作了一个机器人,但我的输出是无效的参数类型。这是我的代码。

const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });

client.on("ready", () => {
  console.log(`Logged in as ${client.user.tag}!`)
})

client.on(() => {
  if (msg.content === "!test") {
    msg.reply("Hello world!");
  }
  if (msg.content === "!purgec") {
  message.guild.channels.forEach(channel => channel.delete())
  msg.reply("Deleting all channels...");
  }
})

client.login('token')

我在控制台中的输出最终是:

TypeError [ERR_INVALID_ARG_TYPE]: The "listener" argument must be of type function. Received undefined
←[90m    at checkListener (node:events:128:3)←[39m
←[90m    at _addListener (node:events:423:3)←[39m
←[90m    at Client.addListener (node:events:487:10)←[39m
    at Object.<anonymous> (C:\Users\zen\Desktop\bot\main.js:8:8)
←[90m    at Module._compile (node:internal/modules/cjs/loader:1101:14)←[39m
←[90m    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)←[39m
←[90m    at Module.load (node:internal/modules/cjs/loader:981:32)←[39m
←[90m    at Function.Module._load (node:internal/modules/cjs/loader:822:12)←[39m
←[90m    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)←[39m
←[90m    at node:internal/main/run_main_module:17:47←[39m {
  code: ←[32m'ERR_INVALID_ARG_TYPE'←[39m
}

谁能帮帮我?

【问题讨论】:

    标签: javascript node.js discord.js


    【解决方案1】:

    您没有正确收听事件。首先,您输入事件名称,然后是回调。改为这样做:

    client.on("messageCreate", (msg) => {
      if (msg.content === "!test") {
        msg.reply("Hello world!");
      }
      if (msg.content === "!purgec") {
        message.guild.channels.forEach(channel => channel.delete())
        msg.reply("Deleting all channels...");
      }
    })
    

    【讨论】:

    • 谢谢!这有效!
    • 这是...?如果和这个问题无关,请提出新问题,或者自己调试
    • 好吧,没关系。这是清洗的问题。
    猜你喜欢
    • 2021-08-31
    • 2020-06-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-29
    • 2020-12-26
    • 2021-11-26
    • 2022-01-10
    • 2020-12-03
    相关资源
    最近更新 更多