问题
I am trying to make my bot replying to any DM sent to it.
So I currently have this:
client.on('msg', () => {
if (msg.channel.DMChannel) {
msg.reply("You are DMing me now!");
}
});
But unfortunately, it does not reply to any DM.
I've tried to replace msg.channel.DMChannel with msg.channel.type == 'dm' but this didn't work.
I also tried to replace msg.reply with msg.author.send and msg.channel.send but they all didn't work.
Any help would be appreciated.
Thanks!
回答1:
On the official documentation I don't see mentioned the event client.on('msg') only client.on('message').
With that out of the way:
client.on('message', msg => {
if (msg.channel.type == "dm") {
msg.author.send("You are DMing me now!");
return;
}
});
Just tried this and worked without any issues.
回答2:
Your function isn't receiving the proper 'msg' object, try this:
client.on('message', async message => {
if (message.channel.type == 'dm') {
message.reply("You are DMing me now!");
}
});
Edit: I referenced sample code here to come to this conclusion. Maybe this link will help you in the future. Good luck!
来源:https://stackoverflow.com/questions/51614795/how-to-reply-to-any-dms-sent-to-the-bot