TypeError:无法读取未定义的属性“ channels”

时间:2020-08-20 05:08:32

标签: discord.js

我对Java没有经验,所以我按照一些教程在单独的文件中使用了不同的命令,它们可以正常工作,但是我无法修复msg命令中的错误:

module.exports = {
    name: 'msg',
    description: 'sends a message to any channel the bot can access',
    execute(message, args){
        
        var msg = args.slice(1);
        msg = msg.join(" ");
        //let channel = Vot.channels.cache.get(args[1])
       let server = args[0]
       
       if(!server) return message.channel.send(msg);
       if(!msg) return message.reply("where is the message");

Vot.channels.cache.get(server).send(msg);
 }
}

其应为.@msg (channel_id) <message>,将邮件发送到所需的频道 (它曾在主文件的switch语句中起作用过)我曾尝试过其他问题的解决方案,例如顶部的const { client } = require('../Server.js'),但它没有起作用,还有其他选择吗?

1 个答案:

答案 0 :(得分:0)

您应该使用message.client而不是Vot

module.exports = {
    name: 'msg',
    description: 'sends a message to any channel the bot can access',
    execute(message, args){
        
        var msg = args.slice(1);
        msg = msg.join(" ");
        //let channel = message.client.channels.cache.get(args[1])
       let server = args[0]
       
       if(!server) return message.channel.send(msg);
       if(!msg) return message.reply("where is the message");

message.client.channels.cache.get(server).send(msg);
 }
}