accept user ID's

This commit is contained in:
Emily 2021-03-07 01:15:07 +11:00
parent abe8c824e3
commit c58df67896
4 changed files with 58 additions and 38 deletions

View file

@ -36,7 +36,9 @@ module.exports = class {
return; return;
} }
if (action.toLowerCase() !== 'add' || action.toLowerCase() !== 'remove') { action = action.toLowerCase();
if (action !== 'add' & action !== 'remove') {
return message.channel.createMessage(`${client.emojis.userError} You didn't specify a valid action. Usage: \`${this.help.usage}\``); return message.channel.createMessage(`${client.emojis.userError} You didn't specify a valid action. Usage: \`${this.help.usage}\``);
} }
@ -44,17 +46,27 @@ module.exports = class {
`${client.emojis.userError} You didn't specify a user. Usage: \`${message.prefix + this.help.usage}\`` `${client.emojis.userError} You didn't specify a user. Usage: \`${message.prefix + this.help.usage}\``
); );
let member = message.mentions[0]; let member;
if (!member) member = await message.channel.guild.searchMembers(user.join(' '), 2); if (message.mentions.length > 0) {
member = await client.functions.getMember(message.channel.guild, message.mentions[0].id);
} else {
member = await client.functions.validateUserID(message.channel.guild, user[0]);
if (member.length > 1) return message.channel.createMessage( if (!member) {
`${client.emojis.userError} Found more than one user, try refining your search or pinging the user instead.` member = await message.channel.guild.searchMembers(user.join(' '), 2);
);
if (member.length === 0) return message.channel.createMessage(
action = action.toLowerCase(); `${client.emojis.userError} No users found. Check for mispellings, or ping the user instead.`
);
member = member[0];
if (member.length > 1) return message.channel.createMessage(
`${client.emojis.userError} Found more than one user, try refining your search or pinging the user instead.`
);
member = member[0];
}
}
const blocklist = data.guild.blocklist; const blocklist = data.guild.blocklist;

View file

@ -18,30 +18,34 @@ module.exports = class {
async run (client, message, args, data) { //eslint-disable-line no-unused-vars async run (client, message, args, data) { //eslint-disable-line no-unused-vars
let user = message.author; let member = message.member;
if (args[0]) { if (args[0]) {
user = message.mentions[0]; if (message.mentions.length > 0) {
member = await client.functions.getMember(message.channel.guild, message.mentions[0].id);
} else {
member = await client.functions.validateUserID(message.channel.guild, args[0]);
if (!user) { if (!member) {
user = await message.channel.guild.searchMembers(args.join(' '), 2); member = await message.channel.guild.searchMembers(args.join(' '), 2);
if (user.length < 1) return message.channel.createMessage( if (member.length === 0) return message.channel.createMessage(
`${client.emojis.userError} No users found. Check for mispellings, or ping the user instead.` `${client.emojis.userError} No users found. Check for mispellings, or ping the user instead.`
); );
if (user.length > 1) return message.channel.createMessage( if (member.length > 1) return message.channel.createMessage(
`${client.emojis.userError} Found more than one user, try refining your search or pinging the user instead.` `${client.emojis.userError} Found more than one user, try refining your search or pinging the user instead.`
); );
user = user[0].user; member = member[0];
}
} }
} }
const embed = new client.RichEmbed() const embed = new client.RichEmbed()
.setTitle(user.username + '#' + user.discriminator) .setTitle(member.user.username + '#' + member.user.discriminator)
.setColour(client.functions.displayHexColour(message.channel.guild, user.id)) .setColour(client.functions.displayHexColour(message.channel.guild, member))
.setImage(user.avatarURL); .setImage(member.user.avatarURL);
message.channel.createMessage({ embed: embed }); message.channel.createMessage({ embed: embed });
} }

View file

@ -26,17 +26,21 @@ module.exports = class {
if (message.mentions.length > 0) { if (message.mentions.length > 0) {
member = await client.functions.getMember(message.channel.guild, message.mentions[0].id); member = await client.functions.getMember(message.channel.guild, message.mentions[0].id);
} else { } else {
member = await message.channel.guild.searchMembers(args.join(' '), 2); member = await client.functions.validateUserID(message.channel.guild, args[0]);
if (!member) {
member = await message.channel.guild.searchMembers(args.join(' '), 2);
if (member.length === 0) return message.channel.createMessage( if (member.length === 0) return message.channel.createMessage(
`${client.emojis.userError} No users found. Check for mispellings, or ping the user instead.` `${client.emojis.userError} No users found. Check for mispellings, or ping the user instead.`
); );
if (member.length > 1) return message.channel.createMessage( if (member.length > 1) return message.channel.createMessage(
`${client.emojis.userError} Found more than one user, try refining your search or pinging the user instead.` `${client.emojis.userError} Found more than one user, try refining your search or pinging the user instead.`
); );
member = member[0]; member = member[0];
}
} }
} }

View file

@ -72,7 +72,7 @@ class Functions {
let hexadecimal = object.color.toString(16); let hexadecimal = object.color.toString(16);
while (hexadecimal.length < 6) { while (hexadecimal.length < 6) {
hexadecimal = '0' + hexadecimal; hexadecimal = '0' + hexadecimal;
}; }
return '#' + hexadecimal; return '#' + hexadecimal;
} }