サーバーに参加したときにユーザーに DM を送信する discord.js のコードがいくつかあります。次に、与えられたパスワードを入力する必要があります。これにより、チャネルへのアクセスを許可する役割が与えられます。
const Discord = require('discord.js');
const client = new Discord.Client();
client.once('ready', () => {
console.log('Ready!');
});
client.on('guildMemberAdd', guildMember => {
console.log("Joined");
guildMember.send("Welcome to the server! Please enter the password given to you to gain access to the server:")
.then(function(){
guildMember.awaitMessages(response => message.content, {
max: 1,
time: 300000000,
errors: ['time'],
})
.then((collected) => {
if(response.content === "Pass"){
guildMember.send("Correct password! You now have access to the server.");
}
else{
guildMember.send("Incorrect password! Please try again.");
}
})
.catch(function(){
guildMember.send('You didnt input the password in time.');
});
});
});
client.login("token");
awaitResponses
問題は、関数の使い方がよくわからないことです。私が見つけたすべてのチュートリアルでそれを使用しているため、呼び出す方法がわかりませんmessage.member
。
コードを実行すると、次の 3 つのエラーが発生します。
UnhandledPromiseRejectionWarning: TypeError: guildMember.awaitMessages is not a function
UnhandledPromiseRejectionWarning: 未処理のプロミス拒否。このエラーは、catch ブロックのない非同期関数内でスローしたか、.catch() で処理されなかった promise を拒否したことが原因で発生しました。未処理のプロミス拒否でノード プロセスを終了するには、CLI フラグを使用します--unhandled-rejections=strict
( https://nodejs.org/api/cli.html#cli_unhandled_rejections_modeを参照)。(拒否 ID: 1)
Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.
これらがどの行を指しているのかわからないので、非常に混乱しています。