-
-
Save AllGistsEqual/f25bf844c4f2157137b3d4bc013caeec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bot.on('message', message => { | |
// ping command without a prefix (exact match) | |
if (message.content === 'ping') { | |
const delay = Date.now() - message.createdAt | |
message.reply(`**pong** *(delay: ${delay}ms)*`) | |
return | |
} | |
// ignore all other messages without our prefix | |
if (!message.content.startsWith(prefix)) return | |
// let the bot introduce itself (exact match) | |
if (message.content === `${prefix}who`) { | |
message.channel.send(`My name is ${name} and I was created to serve!`) | |
return | |
} | |
// user info, either call with valid user name or default to info about message author | |
if (message.content.startsWith(`${prefix}whois`)) { | |
// if the message contains any mentions, pick the first as the target | |
if (message.mentions.users.size) { | |
const taggedUser = message.mentions.users.first() | |
message.channel.send( | |
`User Info: ${ | |
taggedUser.username | |
} (account created: ${taggedUser.createdAt.toUTCString()})`, | |
) | |
} else { | |
// default to sender if no user is mentioned | |
const { author } = message | |
message.reply( | |
`User Self Info: ${ | |
author.username | |
} (account created: ${author.createdAt.toUTCString()})`, | |
) | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment