Discord.js向其他频道发送消息



我目前有一个工作脚本,它根据发布者输入的参数分配角色。我想做的是让机器人向本地频道发送一条消息,让发帖者知道它有效,然后向另一个频道发送另一条消息欢迎获得角色的用户加入服务器。这就是我所拥有的:

const { client } = require('../main.js');

module.exports = {
name: 'roles',
description: "This is the command to give new recruits their role!",
args: true,
usage: '<department> <@user>',
execute(message, args){
//variables are defined here
const channel = client.channels.cache.get('the channel id');
message.delete(); //This deletes the posters command message
if (!message.mentions.users.size){
return message.channel.send('Please make sure to tag someone!');

else if(args[0] === 'bcso'){
user.roles.add(bcso);
user.roles.add(member);
user.roles.add(whitelist)
user.roles.remove(leoR);
message.channel.send(`${user} is now a full member of the BCSO`);
channel.send('Message goes here');
}
//rest of my code

但我在控制台上得到的错误是:;TypeError:无法读取未定义的"的属性"channels";

只是为了确认我已经设置了一个高级代码处理程序,所以这个代码在它自己的文件中的命令文件夹中。

想法?

您导入的client似乎没有定义。可能是因为您没有在main.js文件中正确导出它。

幸运的是,您可以简单地使用消息来查找频道。为此,您需要将client.channels.cache.get('the channel id');更改为message.client.channels.cache.get('ID HERE');

最新更新