javascript - 无法在 discord.js 中获取频道
问题描述
所以,我一直在做一个建议命令discord.js
,我不断收到以下错误:
Cannot read property 'channels' of undefined
这是我的代码,我尝试以多种方式更改它,但它不起作用。
module.exports = {
name: "suggestion",
aliases: ['suggest', 'suggestion'],
permissions: [],
description: "suggetion command",
execute(message, args, cmd, client, discord) {
let channel = message.guild.channels.cache.get("865868649839460353");
if (!channel)
return message.reply('A suggestions channel does not exist! Please create one or contact a server administrator.')
.then(message => {
message.delete(6000)
})
.catch(error => {
console.error;
});
}
}
解决方案
第一个想法:您正在执行的频道不是公会。
通过修复此问题,您可以执行以下操作:
if(!message.guild){
return
}
第二个想法:您可能在错误的服务器中指定了错误的频道。请执行下列操作:
let guild = client.guilds.cache.get(`YourGuildId`)
let channel = guild.channels.cache.get(`ChannelId`)
或者
let guild = client.guilds.cache.get(`${message.guild.id}`)
let channel = guild.channels.cache.get(`ChannelId`)
我希望这些想法对你有所帮助!<3
推荐阅读
- javascript - 如何更改滑块中的某些内容
- typescript - 如何在柏树中提取属性值
- string - 使用 bash 删除字符串中特定出现后的所有文本
- node.js - 使用 mongodb 和 multer 在用户中保存 File.path
- android - 通过flutter登录Instagram
- c++ - 初始化指针和矩阵数组
- kubernetes - 将 sidecar 容器日志拖尾到现有 pod
- spring-security - 无法解密 EncryptedData (SAML2)
- google-apps-script - 如何在谷歌脚本中循环谷歌表格粘贴转置公式
- python - Websockets客户端不打印消息——Python