0

I've been working through this for about a week, and I am officially lost. Looking for answers online to how I can adjust this command for /riddle to be daily, and to assign a role upon successfully answering. Any help would be appreciated as I've spent so many hours on this, and now the project is looking for a hard deadline and I'm not able to break through this wall. Please help!

async execute(interaction, message) {
    const item = quiz[Math.floor(Math.random() * quiz.length)];
    const filter = response => {
        return item.answers.some(answer => answer.toLowerCase() === response.content.toLowerCase());
    };
    
    interaction.reply(item.question, { fetchReply: true })
        .then(() => {
            interaction.channel.awaitMessages({ filter, max: 1, time: 30000, errors: ['time'] })
                .then(collected => {
                    interaction.followUp(`${collected.first().author} got the correct answer!`);
                    
                })
                .catch(collected => {
                    interaction.followUp('Looks like you missed the answer this time, come back tomorrow for another chance to find your Fortune! with our daily riddles!');
                });
        });
},

};

  • I have ensured that the bot is at the top of the role hierarchy, and I tried adding under the interaction.followup for correct answers ' member.roles.add(role) ' But it still didn't work. – ZADAN.eth May 12 '22 at 04:42
  • Anytime I add anything after "got the correct answer!" just makes it give me both the correct and incorrect response every time no matter what. – ZADAN.eth May 12 '22 at 04:43

1 Answers1

0

UPDATE:

I have since solved the issue with the roles! My code is now working where it is only showing the random riddle to the user, taking their answer only into account, and responding accordingly to the answer - giving the role on a correct answer.

I'm still looking for how I can wrap all this up into a once per day max call though. If anyone has any insight with that I'd greatly appreciate it.

const {
    SlashCommandBuilder
} = require('@discordjs/builders');
const {
    MessageEmbed,
    MessageAttachment,
    Role
} = require('discord.js');
const {
    $where
} = require('../../schemas/balance');
const Balance = require('../../schemas/balance');
const quiz = require('./quiz.json');

module.exports = {
    data: new SlashCommandBuilder()
        .setName('riddle')
        .setDescription('Get your DAILY Fortune! Riddle and progress through the server!'),

    async execute(interaction, message) {
        const item = quiz[Math.floor(Math.random() * quiz.length)];
        const filter = response => {
            return response.author.id === interaction.user.id;
        };

        interaction.reply({
                content: `${item.question}`,
                ephemeral: true
            })
            .then(() => {
                interaction.channel.awaitMessages({
                        filter,
                        max: 1,
                        time: 30000,
                        errors: ['time']
                    })
                    .then(collected => {
                        console.log(message.guilds)
                        const response = collected.first().content;
                        collected.first().delete();
                        if (item.answers.includes(response.toLowerCase())) {
                            interaction.followUp({
                                content: `${collected.first().author} got the correct answer!`,
                                ephemeral: true
                            });
                            console.log("Riddle Answered Correct");
                            var guild = message.guilds.cache.get('948892863926771722');
                            var role = guild.roles.cache.find(role => role.name === 'Fortune Hunters');
                            var member = guild.members.cache.get(collected.first().author.id);
                            member.roles.add(role);
                        } else {
                            collected.first().delete();
                            interaction.followUp({
                                content: `Looks like you missed the answer this time, come back tomorrow for another chance to find your Fortune! with our daily riddles!`,
                                ephemeral: true
                            });
                            console.log("Riddle Answered Incorrectly");
                        }
                    })
                    .catch(collected => {
                        console.log(collected);
                        interaction.followUp({
                            content: 'You ran out of time!',
                            ephemeral: true
                        });
                        console.log("Timed Out");
                    });
            });
    },
};