问题描述
我##标题##正在获取
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 (将#修改为@)