Haha-Yes/commands/fun/fakebot.js

70 lines
1.7 KiB
JavaScript
Raw Normal View History

2019-08-12 13:47:15 +02:00
const { Command } = require('discord-akairo');
class fakebotCommand extends Command {
constructor() {
super('fakebot', {
aliases: ['fakebot', 'fakeuser', 'fakemember'],
category: 'fun',
clientPermissions: ['MANAGE_WEBHOOKS'],
args: [
{
id: 'member',
type: 'user',
prompt: {
start: 'Who should i fake?',
2019-08-13 23:31:35 +02:00
retry: 'Didn\'t find any user named like that, please say the name again.'
2019-08-12 13:47:15 +02:00
}
},
{
id: 'message',
type: 'string',
prompt: {
2019-08-12 14:18:45 +02:00
start: 'What message should i send?',
2019-08-12 13:47:15 +02:00
},
match: 'rest',
}
],
description: {
content: 'Fake a bot/user with webhook',
2019-08-12 18:41:15 +02:00
usage: '[user] [message]',
examples: ['Supositware#1616 hello!']
2019-08-12 13:47:15 +02:00
}
});
}
async exec(message, args) {
2019-11-01 02:37:27 +01:00
let Attachment = (message.attachments).array();
let url;
// Get attachment link
if (Attachment[0]) {
url = Attachment[0].url;
}
2019-10-17 01:13:39 +02:00
message.channel.createWebhook(args.member.username, {
avatar: args.member.displayAvatarURL(),
reason: `Fakebot/user command triggered by: ${message.author.username}`
})
2019-08-12 18:07:03 +02:00
.then(webhook => {
2019-08-12 18:46:33 +02:00
// Have to edit after creation otherwise the picture doesn't get applied
2019-08-12 18:07:03 +02:00
webhook.edit({
2019-10-17 01:13:39 +02:00
name: args.member.username,
avatar: args.member.displayAvatarURL(),
reason: `Fakebot/user command triggered by: ${message.author.username}`
2019-08-12 13:47:15 +02:00
});
2019-08-12 18:07:03 +02:00
this.client.fetchWebhook(webhook.id, webhook.token)
.then(webhook => {
message.delete();
2019-11-01 02:37:27 +01:00
if (url)
webhook.send(args.message, {files: [url]});
else
webhook.send(args.message);
2019-08-12 18:07:03 +02:00
setTimeout(() => {
webhook.delete();
}, 3000);
2019-08-12 14:05:39 +02:00
});
2019-08-12 18:07:03 +02:00
});
2019-08-12 13:47:15 +02:00
}
}
module.exports = fakebotCommand;