互动赠品(获得互动部分)

时间:2019-11-19 17:34:13

标签: node.js discord discord.js

您好,我想做一个互动式的赠品,我已经拥有互动式的了。

我正在尝试制作交互式的赠品命令,我需要帮助来制作赠品。这是我当前使它具有交互性的代码,我想知道现在如何制作一个带有这些答案格式的赠品命令!谢谢

这是我当前的代码

if(message.content.startsWith(prefix + "giveaway-start")) {

const options = {
 maxMatches: 1
};
     const filter = msg => msg.author.id == message.author.id;
      // request
   message.channel.send(":tada: Giveaway time! What channel will the giveaway be in?");

   // collector
   let collector = await message.channel.awaitMessages(filter, options);
   let answer = collector.first().content;

   message.channel.send("Great! What will you giveaway?");

   // collector
   let collector2 = await message.channel.awaitMessages(filter, options);
   let answer1 = collector2.first().content;

   message.channel.send("Awesome! How long must the giveaway last?");

   // collector
   let collector3 = await message.channel.awaitMessages(filter, options);
   let answer2 = collector3.first().content;

   message.channel.send("Finally! How many winners shall there be?");

   // collector
   let collector4 = await message.channel.awaitMessages(filter, options);
   let answer3 = collector4.first().content;

   // response
   await message.reply(`:tada: Giveaway! Your giveaway in ${answer} of ${answer1} will last ${answer2} and have ${answer3} winners!`);

1 个答案:

答案 0 :(得分:0)

使用@Androz npm软件包:https://www.npmjs.com/package/discord-giveaways

我做到了,尽管无法设置频道。 希望这对您有帮助。

    client.on("message", (message) => {

        const ms = require("ms"); // npm install ms
        const args = message.content.slice(settings.prefix.length).trim().split(/ +/g);
        const command = args.shift().toLowerCase();

        if (command === "giveaway-start") {
            const options = {
                maxMatches: 1
            };
            const filter = msg => msg.author.id == message.author.id;
            // request
            message.channel.send(":tada: Giveaway time! What will you giveaway?");
            // collector
            let collector = await message.channel.awaitMessages(filter, options);
            let answer = collector.first().content;

            message.channel.send("Awesome! How long must the giveaway last?");

            // collector
            let collector1 = await message.channel.awaitMessages(filter, options);
            let answer1 = collector.first().content;

            message.channel.send("Finally! How many winners shall there be?");

            // collector
            let collector2 = await message.channel.awaitMessages(filter, options);
            let answer2 = collector1.first().content;

            // response
            await message.reply(`:tada: Giveaway! Your giveaway of ${answer} will 
          last ${answer1} and have ${answer2} winners!`);


            if (command === "start-giveaway") {
                // g!start-giveaway 2d 1 Awesome prize!
                // will create a giveaway with a duration of two days, with one winner and the prize will be "Awesome prize!"

                giveaways.start(message.channel, {
                    prize: answer,
                    time: answer1,
                    winnersCount: answer2
                }).then((gData) => {
                    console.log(gData); // {...} (messageid, end date and more)
                });
                // And the giveaway is started!
            }
        }
    });