#How do I prevent code from running in DMs

4 messages · Page 1 of 1 (latest)

cunning carbon
#

I have a variable called staffRole and when a user has sent a message using the messageCreate event.

I use const staffrole = message.member.role.cache.some(role => STAFF_ROLES.includes(role.id)); which works perfectly for server messages, but when I message the bot or the bot messages me, then my bot would crash since users don't have any roles in a DM.

Is there a way to prevent this code from running via DMs?

rotund flaxBOT
#

• What's your exact discord.js npm list discord.js and node node -v version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.

rotund flaxBOT