前提
Discord Developer Portalの Privileged Gateway Intents 設定にて以下の設定がONになっている
- MESSAGE CONTENT INTENT
なぜ動かないのか
v14から追加された新しいインテント GatewayIntentBits.MessageContent
が付与されてないから動かない
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent]});
client.on('ready', () => {
console.log("Client have been launched.");
});
client.on('messageCreate', async (message) => {
if(message.content === "!ping") {
message.reply("Pong!")
}
});
これ、ドキュメントにすら書いてない(または書いてあるけどどっかに埋もれてる)
しかも、これがないとnullではなく空文字列が返ってくるという始末
参考
message.content doesn't have any value in Discord.js v14 - stackoverflow