Module Discord.JS宣布命令问题

Module Discord.JS宣布命令问题,module,discord.js,fs,Module,Discord.js,Fs,我正在尝试使用丰富的嵌入为我的bot构建一个annound命令 这是我的announce.js文件: const Discord=require('Discord.js'); module.exports={ 名称:“宣布”, 描述:'发送公告', 吉登利:是的, 执行(消息,参数){ console.log(“嵌入”) const embed=new Discord.RichEmbed() .setTitle(“公告”) .setDescription(“一名工作人员发送了公告”) .setC

我正在尝试使用丰富的嵌入为我的bot构建一个annound命令

这是我的
announce.js
文件:

const Discord=require('Discord.js');
module.exports={
名称:“宣布”,
描述:'发送公告',
吉登利:是的,
执行(消息,参数){
console.log(“嵌入”)
const embed=new Discord.RichEmbed()
.setTitle(“公告”)
.setDescription(“一名工作人员发送了公告”)
.setColor(0x00AE86)
.setFooter(“监护人”https://raw.githubusercontent.com/phantomdev-github/Resources/master/Discord%20Bots/Guardian/src/avatar.png")
.set缩略图(“https://raw.githubusercontent.com/phantomdev-github/Resources/master/Discord%20Bots/Guardian/src/avatar.png")
.setTimestamp()文件
.setURL(“https://github.com/phantomdev-github/Resources/tree/master/Discord%20Bots/Guardian")
.addBlankField(真)
.addField(“公告”,“此处的消息内容”,错误))
message.channel.send({embed});
}
};
我在发布后重建了它,花了一段时间才回到这篇文章。我正在尝试将我的bot中的所有消息重新构建到富嵌入中。因此,代码不同。我还简化了我的
fs
命令和事件处理程序

indexjs

const fs=require('fs');
const Discord=require('Discord.js');
const client=new Discord.client();
const{token}=require('./token.json');
client.commands=new Discord.Collection();
const commandFiles=fs.readdirSync('./commands').filter(file=>file.endsWith('.js'));
for(命令文件的常量文件){
const command=require(`./commands/${file}`);
client.commands.set(command.name,command);
console.log(文件、命令)
}
fs.readdir(“./events/”,(错误,文件)=>{
if(err)返回控制台。error(err);
files.forEach(文件=>{
如果(!file.endsWith('.js'))返回;
const eventFunction=require(`./events/${file}`);
console.log(eventFunction)
eventFunction.execute(客户端)
});
});
client.login(令牌);
message.js

const{prefix}=require('./prefix.json');
module.exports={
名称:'消息',
描述:“客户端消息事件”,
执行:功能(客户端){
client.on('message',message=>{
如果(!message.content.startsWith(prefix)| | message.author.bot)返回;
const args=message.content.slice(prefix.length.split(+/);
const命令=args.shift().toLowerCase();
如果(!client.commands.has(command))返回;
试一试{
client.commands.get(command).execute(message,args);
}捕获(错误){
控制台错误(error);
message.reply('尝试执行该命令时出错!');
}
})
}};
基本上,我需要知道为
“此处的消息内容”
放置什么,以便将键入的消息发布到
#公告
频道

我的问题是如何将公告消息放入richEmbed的
.addField
部分

会不会是类似这样的事情

const Discord=require('Discord.js');
module.exports={
名称:“宣布”,
描述:“将公告发送到指定的频道。”,
吉登利:是的,
执行(消息,参数){
console.log(“嵌入”)
在这里输入代码
if(args.length<2)返回/*错误消息*/;
让channel=message.indications.channels.first();
如果(!通道)返回;
让announcement=args.slice(1.join)(“”);
const embed=new Discord.RichEmbed()
.setTitle(“注意!”)
.setDescription(“来自PhantomDEV工作人员的公告!”)
.setColor(0x00AE86)
.setFooter(“监护人”https://raw.githubusercontent.com/phantomdev-github/Resources/master/Discord%20Bots/Guardian/src/avatar.png")
.set缩略图(“https://raw.githubusercontent.com/phantomdev-github/Resources/master/Discord%20Bots/Guardian/src/avatar.png")
.setTimestamp()文件
.setURL(“https://github.com/phantomdev-github/Resources/tree/master/Discord%20Bots/Guardian")
.addBlankField(真)
.addField(“消息”,“假”);
message.channel.send({embed});
.catch(控制台错误);
};

消息
事件结束时,使用此行调用命令的执行

command.execute(消息,参数);
定义您的
execute
函数以使用所需的
args
参数。另外,这是您在声明
频道时要寻找的方法。您的函数应该是这样的

execute:function(消息,参数){
if(args.length<2)返回/*错误消息*/;
//小心使用;如果只提供了公告
//它提到了一个频道,这个频道将被使用。
让channel=message.indications.channels.first();
如果(!channel)返回/*错误消息*/;
让announcement=args.slice(1.join)(“”);
频道发送(公告)
.catch(控制台错误);
}

无需在执行函数中检查命令是否为“宣布”,因为只有在命令为“宣布”时才会调用该命令。

module.exports.execute()
不使用
command
args
参数,并且这些变量在函数中的任何位置都没有定义。
message.notices.channels()
也不是方法;
message.indications.channels
是返回集合的属性,因此您可能指的是
message.indications.channels.first()。考虑一个帮助你获得STARTED的概述。首先,我已经看到了,我的是不使用<代码>模块。导出。执行< /COD>。它严格要求仅<代码>模块。导出= {< /代码>任何尝试。