Show nickname if user is in guild

This commit is contained in:
loicbersier 2019-11-29 21:50:22 +01:00
parent 2c395c6552
commit 63515aa73a

View file

@ -8,7 +8,7 @@ class fakebotCommand extends Command {
clientPermissions: ['MANAGE_WEBHOOKS'], clientPermissions: ['MANAGE_WEBHOOKS'],
args: [ args: [
{ {
id: 'member', id: 'user',
type: 'user', type: 'user',
prompt: { prompt: {
start: 'Who should i fake?', start: 'Who should i fake?',
@ -35,20 +35,25 @@ class fakebotCommand extends Command {
async exec(message, args) { async exec(message, args) {
let Attachment = (message.attachments).array(); let Attachment = (message.attachments).array();
let url; let url;
let username = args.user.username;
// Get attachment link // Get attachment link
if (Attachment[0]) { if (Attachment[0]) {
url = Attachment[0].url; url = Attachment[0].url;
} }
// Show nickname if user is in guild
if (message.guild.members.get(args.user.id)) {
username = message.guild.members.get(args.user.id).nickname;
}
message.channel.createWebhook(args.member.username, { message.channel.createWebhook(username, {
avatar: args.member.displayAvatarURL(), avatar: args.user.displayAvatarURL(),
reason: `Fakebot/user command triggered by: ${message.author.username}` reason: `Fakebot/user command triggered by: ${message.author.username}`
}) })
.then(webhook => { .then(webhook => {
// Have to edit after creation otherwise the picture doesn't get applied // Have to edit after creation otherwise the picture doesn't get applied
webhook.edit({ webhook.edit({
name: args.member.username, name: username,
avatar: args.member.displayAvatarURL(), avatar: args.user.displayAvatarURL(),
reason: `Fakebot/user command triggered by: ${message.author.username}` reason: `Fakebot/user command triggered by: ${message.author.username}`
}); });
this.client.fetchWebhook(webhook.id, webhook.token) this.client.fetchWebhook(webhook.id, webhook.token)
@ -61,7 +66,9 @@ class fakebotCommand extends Command {
webhook.send(args.message); webhook.send(args.message);
setTimeout(() => { setTimeout(() => {
webhook.delete(); webhook.delete({
reason: `Fakebot/user command triggered by: ${message.author.username}`
});
}, 3000); }, 3000);
}); });
}); });