質問編集履歴
4
文法の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -28,31 +28,35 @@
|
|
28
28
|
|
29
29
|
const Discord = require('discord.js')
|
30
30
|
|
31
|
-
|
31
|
+
const client = new Discord.Client()
|
32
32
|
|
33
33
|
|
34
34
|
|
35
|
-
const GUILD = // 動作させるサーバーのID
|
35
|
+
const GUILD = '123456789' // 動作させるサーバーのID
|
36
36
|
|
37
|
-
const CHANNEL = // 名前を変更するチャンネルのID
|
37
|
+
const CHANNEL = '123456789' // 名前を変更するチャンネルのID
|
38
38
|
|
39
|
-
const CHANNEL2 = //名前変更するチャンネルのID(男性)
|
39
|
+
const CHANNEL2 = '123456789' //名前変更するチャンネルのID(男性)
|
40
40
|
|
41
|
-
const roleID = '' //男性ロールID
|
41
|
+
const roleID = '123456789'; //男性ロールID
|
42
42
|
|
43
43
|
|
44
44
|
|
45
45
|
// ボットがオフラインのときの変更は出来ないから、起動時に辻褄を合わせる
|
46
46
|
|
47
|
-
|
47
|
+
client.on('ready', () => {
|
48
48
|
|
49
|
-
|
49
|
+
|
50
50
|
|
51
|
-
|
51
|
+
const guild = client.guilds.cache.get(GUILD)
|
52
52
|
|
53
|
-
channel
|
53
|
+
const channel = guild.channels.cache.get(CHANNEL)
|
54
54
|
|
55
|
+
let memberCount = guild.roles.cache.get(roleID).members.size;
|
56
|
+
|
57
|
+
channel.setName('メンバー数: ' + memberCount)
|
58
|
+
|
55
|
-
|
59
|
+
})
|
56
60
|
|
57
61
|
|
58
62
|
|
@@ -66,9 +70,9 @@
|
|
66
70
|
|
67
71
|
const channel2 = guild.channels.cache.get(CHANNEL2)
|
68
72
|
|
69
|
-
memberCount = guild.roles.get(roleID).members.size;
|
73
|
+
let memberCount = guild.roles.cache.get(roleID).members.size;
|
70
74
|
|
71
|
-
channel2.setName('男性: ' +
|
75
|
+
channel2.setName('男性: ' + memberCount)
|
72
76
|
|
73
77
|
})
|
74
78
|
|
@@ -78,21 +82,25 @@
|
|
78
82
|
|
79
83
|
// メンバーが参加したらチャンネル名を更新する
|
80
84
|
|
81
|
-
|
85
|
+
client.on('guildMemberAdd', member => {
|
82
86
|
|
83
|
-
|
87
|
+
// 指定したサーバーでのみ実行する
|
84
88
|
|
85
|
-
|
89
|
+
if (member.guild.id === GUILD) {
|
86
90
|
|
87
|
-
|
91
|
+
// チャンネルを取得して、名前を更新する
|
88
92
|
|
89
|
-
|
93
|
+
|
90
94
|
|
91
|
-
channel
|
95
|
+
const channel = member.guild.channels.cache.get(CHANNEL)
|
92
96
|
|
93
|
-
|
97
|
+
let memberCount = guild.roles.cache.get(roleID).members.size;
|
94
98
|
|
99
|
+
channel.setName('メンバー数: ' + memberCount)
|
100
|
+
|
101
|
+
}
|
102
|
+
|
95
|
-
|
103
|
+
})
|
96
104
|
|
97
105
|
|
98
106
|
|
@@ -108,11 +116,11 @@
|
|
108
116
|
|
109
117
|
|
110
118
|
|
111
|
-
const channel
|
119
|
+
const channel = member.guild.channels.cache.get(CHANNEL2)
|
112
120
|
|
113
|
-
memberCount = guild.roles.get(roleID).members.size;
|
121
|
+
let memberCount = guild.roles.cache.get(roleID).members.size;
|
114
122
|
|
115
|
-
channel.setName('男性: ' + member
|
123
|
+
channel.setName('男性: ' + memberCount)
|
116
124
|
|
117
125
|
}
|
118
126
|
|
@@ -122,19 +130,23 @@
|
|
122
130
|
|
123
131
|
|
124
132
|
|
125
|
-
|
133
|
+
// メンバーが退出したらチャンネル名を更新する(処理は上と同じ)
|
126
134
|
|
127
|
-
|
135
|
+
client.on('guildMemberRemove', member => {
|
128
136
|
|
129
|
-
|
137
|
+
if (member.guild.id === GUILD) {
|
130
138
|
|
131
|
-
|
139
|
+
|
132
140
|
|
133
|
-
channel
|
141
|
+
const channel = member.guild.channels.cache.get(CHANNEL)
|
134
142
|
|
135
|
-
|
143
|
+
let memberCount = guild.roles.cache.get(roleID).members.size;
|
136
144
|
|
145
|
+
channel.setName('メンバー数: ' + memberCount)
|
146
|
+
|
147
|
+
}
|
148
|
+
|
137
|
-
|
149
|
+
})
|
138
150
|
|
139
151
|
|
140
152
|
|
@@ -148,11 +160,11 @@
|
|
148
160
|
|
149
161
|
|
150
162
|
|
151
|
-
const channel
|
163
|
+
const channel = member.guild.channels.cache.get(CHANNEL2)
|
152
164
|
|
153
|
-
memberCount = guild.roles.get(roleID).members.size;
|
165
|
+
let memberCount = guild.roles.cache.get(roleID).members.size;
|
154
166
|
|
155
|
-
channel.setName('男性: ' + member
|
167
|
+
channel.setName('男性: ' + memberCount)
|
156
168
|
|
157
169
|
}
|
158
170
|
|
@@ -170,4 +182,8 @@
|
|
170
182
|
|
171
183
|
|
172
184
|
|
185
|
+
|
186
|
+
|
187
|
+
|
188
|
+
|
173
189
|
```
|
3
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -38,7 +38,7 @@
|
|
38
38
|
|
39
39
|
const CHANNEL2 = //名前変更するチャンネルのID(男性)
|
40
40
|
|
41
|
-
const roleID = ''
|
41
|
+
const roleID = '' //男性ロールID
|
42
42
|
|
43
43
|
|
44
44
|
|
2
タグの追加
test
CHANGED
File without changes
|
test
CHANGED
File without changes
|
1
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -166,7 +166,7 @@
|
|
166
166
|
|
167
167
|
//Botの起動とDiscordサーバーへの接続
|
168
168
|
|
169
|
-
client.login("
|
169
|
+
client.login("Botのトークン")
|
170
170
|
|
171
171
|
|
172
172
|
|