我应该添加什么才能使此 /命令在正确的答案中发挥作用,而每天只能呼唤一次?

发布于 2025-01-28 06:35:45 字数 1019 浏览 2 评论 0原文

我已经度过了大约一个星期,我正式迷失了。在网上寻找答案,以便如何调整此命令,以使 /谜语每天都在成功回答时分配角色。任何帮助都将不胜感激,因为我花了很多时间为此,现在该项目正在寻找一个艰难的截止日期,而且我无法突破这堵墙。请帮忙!

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'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!');
                });
        });
},

};

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笔芯 2025-02-04 06:35:45

更新:

从那以后,我就解决了问题!我的代码现在正在使用仅向用户显示随机谜语,仅考虑其答案并相应地回答答案 - 在正确的答案中扮演角色。

我仍在寻找如何将所有这些都包裹在每天一次的最大电话中。如果有人对此有任何见识,我将非常感谢。

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");
                    });
            });
    },
};

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");
                    });
            });
    },
};

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文