New way to handle args

pull/1/head
Supositware 2 years ago
parent f82ff3d380
commit 8d59ac37a6

@ -13,11 +13,11 @@ export default {
async execute(interaction, args, client) {
const leave = await db.leaveChannel.findOne({ where: { guildID: interaction.guild.id } });
if (!leave && !args[0]) {
if (!leave && !args.message) {
return interaction.reply({ content: 'You need a message for me to say anything!', ephemeral: true });
}
else if (!leave) {
const body = { guildID: interaction.guild.id, channelID: interaction.channel.id, message: args[0] };
const body = { guildID: interaction.guild.id, channelID: interaction.channel.id, message: args.message };
await db.leaveChannel.create(body);
return interaction.reply({ content: `The leave message have been set with ${args.message}`, ephemeral: true });
}
@ -48,12 +48,12 @@ export default {
if (!interactionMenu.isButton) return;
interactionMenu.update({ components: [] });
if (interactionMenu.customId === 'edit') {
if (!args[0]) {
if (!args.message) {
return interaction.reply({ content: 'You need to input a message for me to edit!', ephemeral: true });
}
const body = { guildID: interaction.guild.id, channelID: interaction.channel.id, message: args[0] };
const body = { guildID: interaction.guild.id, channelID: interaction.channel.id, message: args.message };
await db.leaveChannel.update(body, { where: { guildID: interaction.guild.id } });
return interaction.editReply({ content: `The leave message has been set to ${args[0]}`, ephemeral: true });
return interaction.editReply({ content: `The leave message has been set to ${args.message}`, ephemeral: true });
}
else if (interactionMenu.customId === 'remove') {
db.leaveChannel.destroy({ where: { guildID: interaction.guild.id, channelID: interaction.channel.id } });

@ -13,13 +13,13 @@ export default {
async execute(interaction, args, client) {
const join = await db.joinChannel.findOne({ where: { guildID: interaction.guild.id } });
if (!join && !args[0]) {
if (!join && !args.message) {
return interaction.reply({ content: 'You need a message for me to say anything!', ephemeral: true });
}
else if (!join) {
const body = { guildID: interaction.guild.id, channelID: interaction.channel.id, message: args[0] };
const body = { guildID: interaction.guild.id, channelID: interaction.channel.id, message: args.message };
await db.joinChannel.create(body);
return interaction.reply({ content: `The join message have been set with ${args[0]}`, ephemeral: true });
return interaction.reply({ content: `The join message have been set with ${args.message}`, ephemeral: true });
}
@ -49,12 +49,12 @@ export default {
if (!interactionMenu.isButton) return;
interactionMenu.update({ components: [] });
if (interactionMenu.customId === 'edit') {
if (!args[0]) {
if (!args.message) {
return interaction.reply({ content: 'You need to input a message for me to edit!', ephemeral: true });
}
const body = { guildID: interaction.guild.id, channelID: interaction.channel.id, message: args[0] };
const body = { guildID: interaction.guild.id, channelID: interaction.channel.id, message: args.message };
await db.joinChannel.update(body, { where: { guildID: interaction.guild.id } });
return interaction.editReply({ content: `The join message has been set to ${args[0]}`, ephemeral: true });
return interaction.editReply({ content: `The join message has been set to ${args.message}`, ephemeral: true });
}
else if (interactionMenu.customId === 'remove') {
db.joinChannel.destroy({ where: { guildID: interaction.guild.id, channelID: interaction.channel.id } });

@ -16,7 +16,7 @@ export default {
.setRequired(true)),
category: 'fun',
async execute(interaction, args) {
let board = args[0];
let board = args.board;
if (fourChan[board] == undefined) {
return interaction.reply({ content: 'Uh oh! The board you are looking for does not exist? You think this is a mistake? Please send a feedback telling me so!', ephemeral: true });

@ -20,12 +20,12 @@ export default {
clientPermissions: [ PermissionFlagsBits.ManageWebhooks ],
async execute(interaction, args) {
await interaction.deferReply({ ephemeral: true });
const member = args[0];
const message = args[1];
const attachment = args[2];
const member = args.user;
const message = args.message;
const attachment = args.image;
const webhook = await interaction.channel.createWebhook(member.user.username, {
const webhook = await interaction.channel.createWebhook({
name: member.user.username,
avatar: member.user.displayAvatarURL(),
reason: `Fakebot/user command triggered by: ${interaction.user.username}`,
});

@ -13,7 +13,7 @@ export default {
category: 'fun',
async execute(interaction, args) {
await interaction.deferReply({ ephemeral: false });
const subreddit = args[0];
const subreddit = args.subreddit;
fetch('https://www.reddit.com/r/' + subreddit + '.json?limit=100').then((response) => {
return response.json();
}).then((response) => {

@ -27,8 +27,8 @@ export default {
ratelimit: 3,
cooldown: 3600,
async execute(interaction, args, client) {
const content = args[0];
const attachment = args[1];
const content = args.content;
const attachment = args.image;
if (!content && !attachment) {
return interaction.reply({ content: 'Uh oh! You are missing any content for me to tweet!', ephemeral: true });

@ -16,7 +16,7 @@ export default {
.setRequired(false)),
category: 'fun',
async execute(interaction, args) {
if (!interaction.channel.nsfw && !args[0]) return interaction.reply(`Please execute this command in an NSFW channel ( Content might not be NSFW but since the video are user submitted better safe than sorry ) OR do \`\`${prefixs[0]}ytp --force\`\` to make the command work outside of nsfw channel BE AWARE THAT IT WON'T CHANGE THE FINAL RESULT SO NSFW CAN STILL HAPPEN`);
if (!interaction.channel.nsfw && !args.force) return interaction.reply(`Please execute this command in an NSFW channel ( Content might not be NSFW but since the video are user submitted better safe than sorry ) OR do \`\`${prefixs[0]}ytp --force\`\` to make the command work outside of nsfw channel BE AWARE THAT IT WON'T CHANGE THE FINAL RESULT SO NSFW CAN STILL HAPPEN`);
// Read userVid folder and select random vid and only take .mp4
const mp4 = [];
@ -50,7 +50,7 @@ export default {
resources: './asset/ytp/resources/',
temp: os.tmpdir(),
sourceList: asset,
intro: args[0] ? './asset/ytp/intro.mp4' : null,
intro: args.force ? './asset/ytp/intro.mp4' : null,
outro: './asset/ytp/outro.mp4',
OUTPUT_FILE: `${os.tmpdir()}/${interaction.id}_YTP.mp4`,
MAX_CLIPS: MAX_CLIPS,

@ -10,7 +10,7 @@ export default {
.setRequired(true)),
category: 'secret',
async execute(interaction, args) {
const command = args[0];
const command = args.something;
if (command === 'levertowned') {
interaction.reply('Hello buddy bro <:youngtroll:488559163832795136> <@434762632004894746>');

@ -28,9 +28,9 @@ export default {
async execute(interaction, args, c) {
client = c;
const url = args[0];
const format = args[1];
interaction.doCompress = args[2];
const url = args.url;
const format = args.format;
interaction.doCompress = args.compress;
if (interaction.cleanUp) {
cleanUp = interaction.cleanUp;
}

@ -18,7 +18,7 @@ export default {
.setTimestamp();
if (interaction.guild) Embed.addFields({ name: 'Guild', value: `${interaction.guild.name} (${interaction.guild.id})`, inline: true });
Embed.addFields({ name: 'Feedback', value: args[0], inline: true });
Embed.addFields({ name: 'Feedback', value: args.feedback, inline: true });
// Don't let new account use this command to prevent spam
const date = new Date();

@ -7,11 +7,15 @@ const prefixs = prefix.split(',');
export default {
data: new SlashCommandBuilder()
.setName('help')
.setDescription('Displays a list of commands or information about a command.'),
.setDescription('Displays a list of commands or information about a command.')
.addStringOption(option =>
option.setName('command')
.setDescription('The command you want more details about.')),
category: 'utility',
async execute(interaction, args, client) {
if (args[0]) {
const command = client.commands.get(args[0]);
if (args.command) {
const command = client.commands.get(args.command);
if (!command) return interaction.reply(`Did not found any command named \`\`${args.command}\`\`. Please make sure it is a valid command and not an alias.`);
const description = Object.assign({
content: 'No description available.',
usage: '',

@ -17,7 +17,7 @@ export default {
category: 'utility',
async execute(interaction, args) {
await interaction.deferReply({ ephemeral: false });
const url = args[0];
const url = args.url;
if (!await utils.stringIsAValidurl(url)) {
console.error(`Not a url!!! ${url}`);

@ -75,15 +75,17 @@ export default {
}
}
const args = [];
const args = {};
// https://discord-api-types.dev/api/discord-api-types-v10/enum/ApplicationCommandOptionType
interaction.options.data.forEach(arg => {
if (arg.type === 'MENTIONABLE') {
return args.push(arg.member);
let payload = arg.value;
if (arg.type === 9) {
payload = arg.member;
}
else if (arg.type === 'ATTACHMENT') {
return args.push(arg.attachment);
else if (arg.type === 11) {
payload = arg.attachment;
}
args.push(arg.value);
args[arg.name] = payload;
});
await command.execute(interaction, args, client);

@ -262,7 +262,7 @@ export default {
const messageArray = message.content.match(/"[^"]*"|\S+/g).map(m => m.slice(0, 1) === '"' ? m.slice(1, -1) : m);
let commandName = messageArray[1].toLowerCase();
let messageArgs = messageArray.splice(2, messageArray.length);
const messageArgs = messageArray.splice(2, messageArray.length);
// Search for alias
client.commands.find(c => {
@ -368,31 +368,21 @@ export default {
msg.delete();
});
};
if (command.data.options.length > 0) {
// if (command.data.options.length === 1 || command.data.options[command.data.options.length - 1].constructor.name.toLowerCase().includes('attachment')) {
if (command.data.options.length === 1) {
const test = messageArgs.join(' ');
messageArgs = [];
messageArgs.push(test);
const args = {};
for (let i = 0; i < command.data.options.length; i++) {
const arg = command.data.options[i];
const type = arg.constructor.name.toLowerCase();
let payload = messageArgs[i];
if (type.includes('mentionable')) {
payload = message.mentions.members.first();
}
for (let i = 0; i < messageArgs.length; i++) {
const constructorName = command.data.options[i].constructor.name.toLowerCase();
if (constructorName.includes('boolean')) {
messageArgs[i] = (messageArgs[i].toLowerCase() === 'true');
}
if (constructorName.includes('mentionable')) {
messageArgs[i] = message.mentions.members.first();
}
}
if (message.attachments) {
messageArgs.push(Array.from(message.attachments.values())[0]);
else if (type.includes('attachment')) {
payload = message.attachments.first();
}
args[arg.name] = payload;
}
await command.execute(message, messageArgs, client);
await command.execute(message, args, client);
}
catch (error) {
console.error(error);

Loading…
Cancel
Save