不和谐.js建议 - 无法读取未定义的属性'channels'



我一直在做一个建议命令,我不知道目前的问题是什么,请帮助。

module.exports = {
name: 'suggestions',
aliases: ['suggest', 'suggestion'],
permissions: [],
description: 'creates a suggestions!',
execute(message, args, cmd, client, discord){
const channel = message.guild.channels.cache.find(c => c.name === 'suggestions');
if(!channel) return message.channel.send('suggestions channel does not exist!');
}
}

错误信息如下:

TypeError: Cannot read property 'channels' of undefined
at Object.execute (C:UsersMyNameDesktopDiscordBotscommandssuggestions.js:7:39)

这是我的主文件:

const Discord = require('discord.js');
const client = new Discord.Client({ partials: ["MESSAGE", "CHANNEL", "REACTION"]});
client.commands = new Discord.Collection();
client.events = new Discord.Collection();
['command_handler', 'event_handler'].forEach(handler =>{
require(`./handlers/${handler}`)(client, Discord);
})

client.login('MYTOKEN');

我想这里是我运行execute()的地方:

module.exports = (Discord, client, message) => {
const prefix = '-';
if(!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(/ +/);
const cmd = args.shift().toLowerCase();
const command = client.commands.get(cmd) || client.commands.find(a => a.aliases && a.aliases.includes(cmd));
if(command) command.execute(client, message, args, Discord);
}

请尝试定义频道,然后再发送消息

client.channels.cache.get("CHANNELID").send(`TEST`);

这可能是工作;

module.exports = {
name: 'suggestions',
aliases: ['suggest', 'suggestion'],
permissions: [],
description: 'creates a suggestions!',
execute(client, message, args, Discord){ // CHANGED
const channel = message.guild.channels.cache.find(c => c.name === 'suggestions');
if(!channel) return message.channel.send('suggestions channel does not exist!');
}
}

最新更新