Last active
April 17, 2021 02:00
-
-
Save RemiixInc/e335b0291512944439b2feef11ae687f to your computer and use it in GitHub Desktop.
Helper function for allowing mentions and ids discord.js
This file contains hidden or 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
// Channel | |
function channel(args) { | |
if (!args) return false; | |
if (args.startsWith('<#') && args.endsWith('>')) { | |
args = args.slice(2, -1); | |
return client.channels.cache.get(args); | |
} else { | |
if (!client.channels.cache.get(args)) return false; | |
return client.channels.cache.get(args) | |
} | |
} | |
// User | |
function user(args) { | |
if (!args) return false; | |
if (args.startsWith('<@') && args.endsWith('>')) { | |
args = args.slice(2, -1); | |
if (args.startsWith('!')) { | |
args = args.slice(1); | |
} | |
return client.users.cache.get(args); | |
} else { | |
if (!client.users.cache.get(args)) return false; | |
return client.users.cache.get(args) | |
} | |
} | |
// Example Usage | |
/* | |
client.on("message", (message) => { | |
if (message.author.bot || !message.guild) return; | |
if (!message.content.startsWith(prefix)) return; | |
const prefix = "!"; | |
const args = message.content.slice(prefix.length).trim().split(" "); | |
const command = args.shift().toLowerCase(); | |
if (command === "ping") { | |
if (!args.length) return message.channel.send("Mention or provide the id of the user to ping.") | |
const userToPing = user(args[0]) | |
if (!userToPing) return message.channel.send("Mention or provide the VALID id of the user to ping.") | |
message.channel.send("<@" + userToPing.id + ">") | |
} | |
}); | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment