Provides several helper methods for working with discord.js users.
Install:
npm i @aquarius-bot/users
Gets the nickname for a User in a Guild. If the user doesn't have one, it returns their regular name.
Example
import Discord from 'discord.js';
import { getNickname } from '@aquarius-bot/users';
const client = new Discord.Client();
client.on('message', (message) => {
const nickname = getNickname(message.guild, message.author);
message.reply(`Thanks for sending a message ${nickname}!`);
});
Determines if a user is a bot or not.
Example
import Discord from 'discord.js';
import { isBot } from '@aquarius-bot/users';
const client = new Discord.Client();
client.on('message', (message) => {
if (isBot(message.author)) {
message.reply('You are a bot!');
}
});
Determines if a user is streaming or not. Note that this takes a presence and not a user object; this allows it to check against previous presences and not just the current one.
Example
import Discord from 'discord.js';
import { isStreaming } from '@aquarius-bot/users';
const client = new Discord.Client();
client.on('presenceUpdate', (oldPresence, newPresence) => {
if (!isStreaming(oldPresence) && isStreaming(newPresence)) {
console.log(`${oldPresence.user} is now streaming!`);
}
});