久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

當不應該在 discord.js 命令處理程序中未定義時,

Cannot read properties of undefined when it shouldn#39;t be undefined in discord.js command handler(當不應該在 discord.js 命令處理程序中未定義時,無法讀取未定義的屬性)
本文介紹了當不應該在 discord.js 命令處理程序中未定義時,無法讀取未定義的屬性的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我用一個簡單的ping"命令創建了一個小命令處理程序.命令.但是,嘗試訪問 message.channel 顯示未定義.這是為什么呢?

I created a small command handler with a simple "ping" command. However, trying to access message.channel shows up undefined. Why is this?

./index.js

//Discord, fs, prefix, client etc. declarations

client.commands = new Collection()

const files = fs.readdirSync("./commands").filter(file => file.endsWith(".js")

for (const file of files) {
  const command = require(`./commands/${file}`)
  client.commands.set(command.name, command)
}

client.on("messageCreate", message => {
  const [command, ...args] = message.content.slice(prefix.length).split(/ +/g)
  if (client.commands.has(command) {
    client.commands.get(command).execute(message, client, args)
  }
})

client.login(/*token*/)

./commands/ping.js

module.exports = {
  name: "ping",
  description: "Make me say pong",
  async execute(client, message, args) {
    message.channel.send("Pong!")
  }
}

推薦答案

雖然 Message.channel 可能有效,但 message 不是 Message<的實例/代碼>.它實際上是 Client 的一個實例.參數的順序總是很重要,將它們放在錯誤的順序可能會引發 TypeErrors.這里有1個簡單的解決方案

While Message.channel may be valid, message is not an instance of Message. It is actually an instance of Client. The order of the arguments always matter, and putting them in the wrong order can throw TypeErrors. There is 1 simple solution here

按正確的順序排列參數!您可以更改執行或聲明

Make the arguments in the right order! You can either change the execution, or the declaration

client.commands.get(command).execute(client, message, args)

這真的很常見,而且發生的不僅僅是向頻道發送消息

This is really common and happens for more than sending messages to channels

這篇關于當不應該在 discord.js 命令處理程序中未定義時,無法讀取未定義的屬性的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Using discord.js to detect image and respond(使用 discord.js 檢測圖像并響應)
Check if user ID exists in Discord server(檢查 Discord 服務器中是否存在用戶 ID)
Guild Member Add does not work (discordjs)(公會成員添加不起作用(discordjs))
Creating my first bot using REPLIT but always error Discord.JS(使用 REPLIT 創建我的第一個機器人,但總是錯誤 Discord.JS)
How do I code event/command handlers for my Discord.js bot?(如何為我的 Discord.js 機器人編寫事件/命令處理程序?)
How to find a User ID from a Username in Discord.js?(如何從 Discord.js 中的用戶名中查找用戶 ID?)
主站蜘蛛池模板: 一级毛片视频 | 欧美成人精品在线 | 精品无码三级在线观看视频 | 日韩在线不卡 | 成人区精品| 三区在线| 精品国产一区二区三区久久久四川 | 午夜久草 | 岛国在线免费观看 | 色综合色综合色综合 | 亚洲啊v在线 | 91精品国产91久久久久久吃药 | 亚洲综合一区二区三区 | 黄色欧美大片 | 午夜影院在线播放 | 午夜在线 | 久久久久99| 久久av一区| 欧美黑人国产人伦爽爽爽 | 搞av.com | 国产成人精品免费视频 | 日本三级电影在线观看视频 | 中文字幕国产高清 | 成人欧美日韩一区二区三区 | 国产精品中文字幕一区二区三区 | 亚洲在线 | 人成精品 | 免费一级黄色录像 | 精品乱码一区二区 | 毛片免费看 | 日韩一区二区三区在线观看 | 亚洲精品在线免费 | 夜夜爽99久久国产综合精品女不卡 | 久久久久久网站 | 色999日韩 | 91精品国产一区二区三区 | 欧美一级久久 | 国产精品视频97 | 精品亚洲一区二区 | 欧美午夜久久 | 国产精品一区二区精品 |