-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautoPublishAnnounceMessage.js
113 lines (101 loc) · 3.1 KB
/
autoPublishAnnounceMessage.js
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
const http = require("http");
http
.createServer(function (req, res) {
res.write("example.js is active.\nPlease check it.");
res.end();
})
.listen(8080);
// Discord bot implements
const { Client, GatewayIntentBits, ChannelType } = require("discord.js");
require("dotenv").config();
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMessages,
],
});
const prefix = "pj!";
const token = process.env.token;
// botが準備できれば発動され、 上から順に処理される。
client.on("ready", () => {
// コンソールにReady!!と表示
console.log("Ready!!");
// ステータスを設定する
setInterval(() => {
client.user.setActivity({
name: `所属サーバー数は、${client.guilds.cache.size}サーバー| Ping値は、${client.ws.ping}msです`,
});
}, 10000);
client.channels.cache.get("889486664760721418").send("起動しました!");
// readyイベントここまで
});
// botがメッセージを受信すると発動され、 上から順に処理される。
client.on("messageCreate", async (message) => {
if (message.channel.type === ChannelType.GuildAnnouncement) {
// メッセージを「公開」にする
if (message.crosspostable) {
message
.crosspost()
.then(() => {
message.react("✅");
setTimeout(async () => {
let botReactions = message.reactions.cache.filter((reaction) =>
reaction.users.cache.has(client.user.id)
);
try {
for (let reaction of botReactions.values()) {
await reaction.users.remove(client.user.id);
}
} catch (err) {
console.log(err);
}
}, 5000);
}) //メッセージを公開できたらリアクションをする
.catch((err) => {
console.log(err);
});
} else {
message.react("❌"); //Botに権限がない場合
}
}
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).trim().split(" ");
const command = args.shift().toLowerCase();
if (command == "about") {
message.channel.send({
embeds: [
{
title: "Planet bot β (JS)について",
description: "node.jsで作成された、BOT開発テスト用のbotです。",
color: 3823616,
timestamp: new Date(),
thumbnail: {
url: "attachment://logo.png",
},
footer: {
text: "This bot is made by Hoshimikan6490",
icon_url: "attachment://me.png",
},
},
],
files: [
{
attachment: "images/logo.png",
name: "logo.png",
},
{
attachment: "images/me.png",
name: "me.png",
},
],
});
}
});
client.on("interactionCreate", async (interaction) => {
if (interaction.customId === "support") {
await interaction.reply("hi!!!");
}
});
// botログイン
client.login(token);