回答編集履歴

1

最終的なコードを追加

2022/11/17 07:12

投稿

退会済みユーザー
test CHANGED
@@ -3,3 +3,27 @@
3
3
  const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMembers] });
4
4
  ```
5
5
  とありますが、`intents: [(中略)] });`に`GatewayIntentBits.MessageContent`が入っていないのでbotがメッセージの内容を見ることができなくて反応してくれなくなっているんだと思います。
6
+
7
+ ### コード
8
+ ```javascript
9
+ const { Client, GatewayIntentBits } = require('discord.js')
10
+ const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMembers, GatewayIntentBits.MessageContent] });
11
+
12
+ client.once('ready', () => {
13
+ console.log('Ready!'); // 起動した時に"Ready!"とコンソールに出力する
14
+ });
15
+
16
+ client.on("guildMemberAdd", member => {
17
+ if (member.guild.id !== "1020389040475881533") return; // 指定のサーバー以外では動作しないようにする
18
+ member.guild.channels.cache.get("1020389040475881536").send(`${member.user}が参加したでー`);
19
+ });
20
+
21
+ client.on('messageCreate', message => {
22
+ if (message.author.bot) return;
23
+ if (message.content.includes('よお')) {
24
+ message.channel.send('よお');
25
+ }
26
+ });
27
+
28
+ client.login('botトークン');
29
+ ```