You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Haha-Yes/commands/fun/fakebot.js

62 lines
1.6 KiB
JavaScript

5 years ago
const { Command } = require('discord-akairo');
const fs = require('fs');
5 years ago
const reload = require('auto-reload');
5 years ago
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?',
}
},
{
id: 'message',
type: 'string',
prompt: {
start: 'What message should i send?',
5 years ago
},
match: 'rest',
}
],
description: {
content: 'Fake a bot/user with webhook',
usage: '',
examples: ['']
}
});
}
async exec(message, args) {
5 years ago
if (!fs.existsSync(`./webhook/${message.guild.id}_${message.channel.id}.json`)) {
5 years ago
message.channel.createWebhook('fakebot')
.then(webhook => {
fs.writeFile(`./webhook/${message.guild.id}_${message.channel.id}.json`, `{"id": "${webhook.id}", "token": "${webhook.token}", "channel": "${message.channel.id}"}`, function (err) {
5 years ago
if (err) {
console.log(err);
}
return message.channel.send('Please run me again to send the message!');
5 years ago
});
});
} else {
let webhook = reload(`../../webhook/${message.guild.id}_${message.channel.id}.json`);
this.client.fetchWebhook(webhook.id, webhook.token)
.then(webhook => {
webhook.edit({
name: args.member.username,
avatar: args.member.displayAvatarURL()
});
message.delete();
return webhook.send(args.message);
5 years ago
});
}
5 years ago
}
}
module.exports = fakebotCommand;