我如何让一个不和谐的机器人检查它是否正在被私信,然后用 discord.js 回复所说的私信?
How do I make a discord bot check if it is being PMed and then respond to said PM with discord.js?
如何让我的机器人检查用户是否在私信机器人,然后让机器人回复上述消息?
到目前为止我玩过的代码,部分工作正常,例如“sendMessage 和 console.log 和 bot.channels.get 等,但它得到了 运行 的正确语句部分是问题,代码:
// "Help" command for admin assistance
bot.on('message', (message) => {
if(message.channel.DMChannel) {
// Check if the word sent is "help"
if(message.content.toLowerCase() == 'help') {
console.log('User ' + member.user.username + ' is requesting assitance. Now alerting staff members!');
bot.channels.get("397707437781680130").send('**' + member.user.username + '**, is requesting staff assitance. Now alerting staff members!')
bot.sendMessage('I helped you! A staff member will respond soon!');
} else {
bot.sendMessage('You can only ask for help by DM, please type "help" if you need assistance!');
}
}
});
谢谢指点。
Discord.js 有一个内置的 channel.type
可以用来检查 DM 频道(也称为 PM 频道)。
考虑到这一点,您的代码应该类似于:
bot.on('message', (message) => {
if(message.channel.type == "dm") {
//what should happen on a dm
} else {
//what should happen if the channel is not a dm
}
});
如何让我的机器人检查用户是否在私信机器人,然后让机器人回复上述消息?
到目前为止我玩过的代码,部分工作正常,例如“sendMessage 和 console.log 和 bot.channels.get 等,但它得到了 运行 的正确语句部分是问题,代码:
// "Help" command for admin assistance
bot.on('message', (message) => {
if(message.channel.DMChannel) {
// Check if the word sent is "help"
if(message.content.toLowerCase() == 'help') {
console.log('User ' + member.user.username + ' is requesting assitance. Now alerting staff members!');
bot.channels.get("397707437781680130").send('**' + member.user.username + '**, is requesting staff assitance. Now alerting staff members!')
bot.sendMessage('I helped you! A staff member will respond soon!');
} else {
bot.sendMessage('You can only ask for help by DM, please type "help" if you need assistance!');
}
}
});
谢谢指点。
Discord.js 有一个内置的 channel.type
可以用来检查 DM 频道(也称为 PM 频道)。
考虑到这一点,您的代码应该类似于:
bot.on('message', (message) => {
if(message.channel.type == "dm") {
//what should happen on a dm
} else {
//what should happen if the channel is not a dm
}
});