yewshanooi / sodium

Open source discord bot with application commands and a user-friendly interface
https://skyelements.github.io/sodium.html
MIT License
10 stars 4 forks source link

[COMMAND] Botpresence.js file return #26

Closed Manzanitabot123 closed 1 year ago

Manzanitabot123 commented 1 year ago

I am aware that the version of discord.js was recently updated to 14.0.3. I don't know the reasons why you removed the Botpresence.js file, but I would like it to be kept in the current repository. Here is the code modified the way I think it is according to the documentation (unverified):

const { MessageEmbed } = require('discord.js');
const { SlashCommandBuilder, ActivityType } = require('discord.js');
const { embedColor } = require('../config.json');
const noPermission = require('../errors/noPermission.js');

module.exports = {
    data: new SlashCommandBuilder()
        .setName('botpresence')
        .setDescription('Change bot\'s current presence in every server')
        .addStringOption(option => option.setName('activity').setDescription('Enter an activity').setRequired(true))
        .addStringOption(option => option.setName('type').setDescription('Select a type').addChoices({ name: 'Playing', value: 'Playing' }, { name: 'Listening', value: 'Listening' }, { name: 'Watching', value: 'Watching' }, { name: 'Competing', value: 'Competing' }).setRequired(true))
        .addStringOption(option => option.setName('status').setDescription('Select a status').addChoices({ name: 'Online', value: 'online' }, { name: 'Idle', value: 'idle' }, { name: 'Do Not Disturb', value: 'dnd' }, { name: 'Invisible', value: 'invisible' }).setRequired(true)), 
    cooldown: '25',
    guildOnly: true,
    execute (interaction) {
        if (!interaction.member.permissions.has('Administrator')) return interaction.reply({ embeds: [noPermission] });

            const activityField = interaction.options.getString('activity');

            const typeField = interaction.options.getString('type');
                    if (typeField === 'Playing') resultType = ActivityType.Playing;
                    if (typeField === 'Listening') resultType = ActivityType.Listening;
                    if (typeField === 'Watching') resultType = ActivityType.Watching;
                    if (typeField === 'Competing') resultType = ActivityType.Competing;

            const statusField = interaction.options.getString('status');

                let resultStatus;
                    if (statusField === 'online') resultStatus = 'Online';
                    if (statusField === 'idle') resultStatus = 'Idle';
                    if (statusField === 'dnd') resultStatus = 'Do Not Disturb';
                    if (statusField === 'invisible') resultStatus = 'Invisible';

            const embed = new MessageEmbed()
                .setDescription('Successfully changed bot\'s presence')
                .addFields(
                    { name: 'Activity', value: `${activityField}` },
                    { name: 'Type', value: `\`${typeField}\``, inline: true },
                    { name: 'Status', value: `\`${resultStatus}\``, inline: true }
                )
                .setColor(embedColor);

            interaction.client.user.setPresence({ activities: [{ name: `${activityField}`, type: resultType }], status: `${statusField}` });
                interaction.reply({ embeds: [embed] });
        }
};

By the way, I like the simple but complete structure of this repository and I appreciate your effort.

It should be noted that this is not really a problem, but rather a suggestion with no malicious intent or intent to annoy, so feel free to ignore this "issue" if you wish.