roleinfo command fixes
parent
e3dd49e3a8
commit
b904a00b33
|
@ -12,26 +12,24 @@ export default class Roleinfo extends Command {
|
|||
this.enabled = true;
|
||||
}
|
||||
|
||||
public async run(message: Message, args: any) {
|
||||
public async run(message: Message, args: string[]) {
|
||||
try {
|
||||
if (!args[0]) return this.client.createMessage(message.channel.id, `${this.client.util.emojis.ERROR} You need to specifiy a role ID or a role name.`);
|
||||
if (!args[0]) return message.channel.createMessage(`***${this.client.util.emojis.ERROR} You need to specifiy a role ID or a role name.***`);
|
||||
|
||||
let role: any;
|
||||
if (!Number.isNaN(args[0])) { // if it's a role id
|
||||
// @ts-ignore
|
||||
role = message.channel.guild.roles.find((r: Role) => r.id === args[0]);
|
||||
} else if (Number.isNaN(args[0])) { // if it's a role name
|
||||
let role: Role = message.channel.guild.roles.find((r: Role) => r.id === args[0]);
|
||||
if (!role) { // if it's a role name
|
||||
// @ts-ignore
|
||||
role = message.channel.guild.roles.find((r: Role) => r.name === args.join(' '));
|
||||
role = message.channel.guild.roles.find((r: Role) => r.name.toLowerCase().includes(args.join(' ').toLowerCase()));
|
||||
}
|
||||
if (!role) return this.client.createMessage(message.channel.id, `${this.client.util.emojis.ERROR} Could not find role.`);
|
||||
if (!role) return this.client.createMessage(message.channel.id, `***${this.client.util.emojis.ERROR} Could not find role.***`);
|
||||
|
||||
const ms = role.createdAt;
|
||||
const date = new Date(ms).toLocaleDateString('en-us');
|
||||
const time = new Date(ms).toLocaleTimeString('en-us');
|
||||
|
||||
const perms = role.permissions;
|
||||
let permsArray: any = [];
|
||||
const permsArray: string[] = [];
|
||||
if (perms.has('administrator')) permsArray.push('Administrator');
|
||||
if (perms.has('manageGuild')) permsArray.push('Manage Server');
|
||||
if (perms.has('manageChannels')) permsArray.push('Manage Channels');
|
||||
|
@ -42,15 +40,9 @@ export default class Roleinfo extends Command {
|
|||
if (perms.has('banMembers')) permsArray.push('Ban Members');
|
||||
if (perms.has('kickMembers')) permsArray.push('Kick Members');
|
||||
|
||||
let hasPerms: boolean;
|
||||
if (permsArray.length > 0) {
|
||||
permsArray = permsArray.join(', ');
|
||||
hasPerms = true;
|
||||
}
|
||||
|
||||
const embed = new RichEmbed();
|
||||
embed.setTitle('Role Information');
|
||||
embed.setDescription(`<@&${role.id}> ID: \`${role.id}\``);
|
||||
embed.setAuthor(`${message.author.username}#${message.author.discriminator}`, message.author.avatarURL);
|
||||
embed.setColor(role.color);
|
||||
embed.addField('Name', role.name, true);
|
||||
embed.addField('Color', `#${role.color.toString(16)}`, true);
|
||||
|
@ -61,8 +53,8 @@ export default class Roleinfo extends Command {
|
|||
embed.setFooter(this.client.user.username, this.client.user.avatarURL);
|
||||
embed.setTimestamp();
|
||||
|
||||
if (hasPerms) {
|
||||
embed.fields.push({ name: 'Permissions', value: permsArray, inline: false });
|
||||
if (permsArray.length > 0) {
|
||||
embed.addField('Permissions', permsArray.join(', '), true);
|
||||
}
|
||||
return message.channel.createMessage({ embed });
|
||||
} catch (err) {
|
||||
|
|
Loading…
Reference in New Issue