-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample003.js
More file actions
49 lines (46 loc) · 2.54 KB
/
Copy pathexample003.js
File metadata and controls
49 lines (46 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const { Client, Intents, MessageEmbed } = require("discord.js");
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
require("dotenv").config();
const UGC = require("union-global-chat.connect.djs");
const ugcClient = new UGC.Client(process.env.UGCTOKEN);
client.login(process.env.BOTTOKEN);
client.on("ready", () => {
console.log(`Logged in as ${client.user.tag}!`);
});
ugcClient.on("ready", () => {
console.log("Authed on UGC!");
});
//グローバルチャット
client.on("messageCreate", message => {
if (message.author?.bot || !message.channel.topic?.match(/tester.gchat/)) return;
ugcClient.sendMessage(message);
message.delete({ timeout: 1000 }).catch((e) => message.channel.send(`メッセージを削除する際にエラーが起きました\nエラー:${e.message}`));
});
//グローバルチャット連携
ugcClient.on("message", async (message) => {
if (message.author.bot) return;
client.channels.cache.forEach(ch => {
if (ch.type == "GUILD_TEXT" && ch.topic?.match(/tester.gchat/)) {
var embed = new MessageEmbed({
title: "",
color: "RANDOM",
description: message.message.content, // メッセージの内容を説明欄に
timestamp: new Date(), // 時間を時間の欄に
footer: {
icon_url: message.guild.iconURL, // フッターのアイコンのURLをメッセージが送信されたサーバーのアイコンのURLに
text: message.guild.name // 文字をサーバーの名前に
},
image: {
url: (message.message.attachments.length) ? message.message.attachments[0].url : null//もしメッセージの中にファイルが有るなら、メッセージの中のはじめのファイルのURLを。無いならnull(無し)を。
},
author: {
name: `${message.author.username}#${message.author.discriminator}`,//メッセージの送信者のタグ付きの名前を送信者名の欄に
url: `https://discord.com/users/${message.author.id}`,//名前を押すとその人のプロフィールが出されるように(https://discord.com/users/ その人のID)
icon_url: message.author.avatarURL//メッセージ送信者のアイコンのURLを送信者のアイコンの欄に
}
});
ch.send({ embeds: [embed] })
.catch(e => console.log(e));
}
});
});