微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

错误:让channel = message.mentions.channels.first^ TypeError:无法读取未定义的属性“ channels”

如何解决错误:让channel = message.mentions.channels.first^ TypeError:无法读取未定义的属性“ channels”

我##标题##正在获取
TypeError:无法读取未定义的属性'channels'。每当我运行命令?setwelcome #welcome 我尝试搜索,但无法提供修复资金。 我不知道怎么回事我该如何解决? 谢谢您的阅读

完整错误日志

The bot is active and ready to go!
/home/runner/avionica/commands/setwelcome.js:12
    let channel = message.mentions.channels.first()
                                   ^

TypeError: Cannot read property 'channels' of undefined
    at Object.execute (/home/runner/avionica/commands/setwelcome.js:12:36)
    at Client.<anonymous> (/home/runner/avionica/index.js:74:47)
    at Client.emit (events.js:327:22)
    at Client.EventEmitter.emit (domain.js:483:12)
    at MessageCreateAction.handle (/home/runner/avionica/node_modules/discord.js/src/client/actions/MessageCreate.js:31:14)
    at Object.module.exports [as MESSAGE_CREATE] (/home/runner/avionica/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32)
    at WebSocketManager.handlePacket (/home/runner/avionica/node_modules/discord.js/src/client/websocket/WebSocketManager.js:384:31)
    at WebSocketShard.onPacket (/home/runner/avionica/node_modules/discord.js/src/client/websocket/WebSocketShard.js:444:22)
    at WebSocketShard.onMessage (/home/runner/avionica/node_modules/discord.js/src/client/websocket/WebSocketShard.js:301:10)
    at WebSocket.onMessage (/home/runner/avionica/node_modules/ws/lib/event-target.js:125:16)

这是index.js

const discord = require('discord.js');
const PREFIX = "?";
const client = new discord.Client();
const { CanvasSenpai } = require("canvas-senpai")
const canva = new CanvasSenpai();
const keep_alive = require('./keep_alive.js');
const config = require('./config.json');
const fs = require('fs');
const db = require("quick.db")
client.commands = new discord.Collection();

//welcome 

client.on("guildMemberAdd",(member) => { //usage of welcome event
  let chx = db.get(`welchannel_${member.guild.id}`); //defining var
  
  if(chx === null) { //check if var have value or not
    return;
  }

  let wembed = new discord.MessageEmbed() //define embed
  .setAuthor(member.user.username,member.user.avatarURL())
  .setColor("#ff2050")
  .setThumbnail(member.user.avatarURL())
  .setDescription(`We are very happy to have you in our server`);
  
  client.channels.cache.get(chx).send(wembed) //get channel and send embed
})

const commandFiles = fs.readdirsync('./commands/').filter(file => file.endsWith('.js'));
for(const file of commandFiles){
    const command = require(`./commands/${file}`);
 
    client.commands.set(command.name,command);
}
 
lient.on('ready',() => {
    console.log("The bot is active and ready to go!");
});

case "setwelcome":
            client.commands.get('setwelcome').execute(message,args,client);
        break;


 
        
    }
 
});


client.login(config.token);

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。