我不知道该如何使我的机器人在作者收到消息后如何用白色对勾标记做出反应,以及当作者未在dms中收到消息时如何用叉号做出反应。这是我的代码:
client.on('message', message => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
if (message.content.startsWith(prefix + 'help')) {
const founder = client.users.get('my id');
message.author.send(`
[❖---------- there's a room called log ----------❖]
1- ? fast connection host
2- ? easy commands
3- ⚠️ working on it everyday
4- ? free for anyone
5- ⚛️ anti-hack
6- Made by one developer : ${founder.username}#${founder.discriminator}
`);
}
});
答案 0 :(得分:0)
User.send()
返回一个Promise,当正确发送消息时,该Promise将被兑现;当漫游器无法发送该消息时,它将被拒绝:您可以使用Promise.then()
和Promise.catch()
来执行不同的操作根据发生的事情
这是一个示例:
client.on('message', message => {
if (!message.content.startsWith(prefix) || message.author.bot) return
if (message.content.startsWith(prefix + 'help')) {
message.author.send('Your message').then(dmMessage => {
// The message has been sent correctly, you can now react to your original message with the tick
message.react('✔️')
}).catch(error => {
// There has been some kind of problem, you should react with the cross
message.react('❌')
})
}
})
答案 1 :(得分:0)
基本上,如果无法发送某人的DM,则会引发错误。因此,如果他们没有收到叉号,要做出回应,只需捕捉这样的错误即可。
client.on('message', message => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
if (message.content.startsWith(prefix + 'help')) {
const founder = client.users.get('my id');
try {
message.author.send(`
[❖---------- there's a room called log ----------❖]
1- ? fast connection host
2- ? easy commands
3- ⚠️ working on it everyday
4- ? free for anyone
5- ⚛️ anti-hack
6- Made by one developer : ${founder.username}#${founder.discriminator}
`);
message.react('✅');
} catch {
message.react('❌');
}
}
});
在这里,如果DM发送,它会带有复选标记,并且如果引发错误(在未发送时发生),它也会带有叉号。
希望这会有所帮助。