How to detect if the author of a message was a Discord bot?

Brandon picture Brandon · Apr 5, 2018 · Viewed 27.2k times · Source

The title explains my question. This question might sound stupid, but how do I detect if the author of a message was a Discord bot?

Thanks.

Answer

André picture André · Apr 5, 2018

If you want to check if a message author is a bot account you can easily do:

if(message.author.bot) return;

This will return if a user is a bot. If it isn't will keep going.
If you want to check if the message author is the logged in bot you can do:

if(message.author.id === client.user.id) return;

This is gonna return if the message author is the bot, it will keep going if its another bot.