discord.jsでグローバルチャット
なんか他のグローバルチャットのコードが長すぎたので短縮
code:globalChat.js
const discord = require("discord.js");
const client = new discord.Client();
client.on("message", message => {
if(message.author.bot || message.channel.name !== "channel name") return;
client.channels.cache.filter(
(ch) =>
ch.name === "channel name" &&
ch.type === "text" &&
ch.id !== message.channel.id
)
.forEach(ch => {
ch.send(
new discord.MessageEmbed()
.setAuthor(message.author.tag, message.author.avatarURL())
.setDescription(message.content)
.setImage(
message.attachments?.map(a => a.url).shift() ?? null
)
.setFooter(message.guild.name, message.guild.iconURL())
.setTimestamp()
);
});
});