Skip to content

Instantly share code, notes, and snippets.

@AllGistsEqual
Created January 18, 2021 20:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AllGistsEqual/f25bf844c4f2157137b3d4bc013caeec to your computer and use it in GitHub Desktop.
Save AllGistsEqual/f25bf844c4f2157137b3d4bc013caeec to your computer and use it in GitHub Desktop.
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