Hello i want to log the messages that the Bot becomes per DM in a Channel that i choose. Is that possible?
Yes, you can log the messages that bot get in the dms
I'll write sample code for you:
bot.on('message', message => {
if (message.channel.type === 'dm'){
// put your code here
console.log(message.content)
}
});
Yes, direct messages to a bot have guild
property set to null
.
client.on("message", msg => {
if (msg.guild == null) {
// your action here, for example
console.log(msg.content);
}
});
You can also use msg.channel.type
to determine the message's channel type.
client.on('message', msg => {
if (msg.channel.type === 'dm') {
channel.send(msg);
}
});
channel
is an object of type TextChannel where you would like your message to be logged to.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.