如何在 discord.js 中创建交互式命令

时间:2021-04-23 10:23:52

标签: discord discord.js

我想知道如何在 discord.js 中制作像赠品机器人这样的交互式赠品命令。 例如:>gcreate,它启动了一个赠品的交互式设置。

1 个答案:

答案 0 :(得分:0)

您可以使用 discord.js 指南中的 Message Collectors 并且类似地存在用于赠品命令的反应收集器,或者您可以使用 discord-giveaways 之类的软件包
这是一个展示如何设置赠品的示例

const prefix = '>g'
const { GiveawaysManager } = require('discord-giveaways');
// Starts updating currents giveaways
const manager = new GiveawaysManager(client, {
    storage: './giveaways.json',
    updateCountdownEvery: 10000,
    hasGuildMembersIntent: false,
    default: {
        botsCanWin: false,
        exemptPermissions: ['MANAGE_MESSAGES', 'ADMINISTRATOR'],
        embedColor: '#FF0000',
        reaction: '?'
    }
});
// We now have a giveawaysManager property to access the manager everywhere!
client.giveawaysManager = manager;

client.on('ready', () => {
    console.log("I'm ready !");
});


client.on('message', (message) => {
    const ms = require('ms'); // npm install ms
    const args = message.content.slice(prefix.length).trim().split(/ +/g);
    const command = args.shift().toLowerCase();

    if (command === 'create') {
        // 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!"

        client.giveawaysManager.start(message.channel, {
            time: ms(args[0]),
            prize: args.slice(2).join(' '),
            winnerCount: parseInt(args[1])
        })
    });
        // This would start the giveaway
    }
});
client.login('TOKEN_HERE');