切换反应页面?

时间:2019-08-01 22:38:46

标签: javascript node.js mongoose discord.js

好吧,所以我希望能够在我的代码中显示超过10个结果,但是页面插入了,所以就像每个页面包含10个结果并使用反应在页面之间切换一样

我当前的代码

const db = require('schemafilelocation')
const Discord = require('discord.js')

db.find({
    ServerID: message.guild.id
}).sort({Coins: -1}).exec((err, res) => {
    if (err) console.log(err)

    let embed = Discord.RichEmbed()
        .setTitle('Leaderboard')

    if (res.length === 0) {
        // for no results
        embed.setColor('RED')
        embed.addField('No data found for this server', 'Please type in chat to gain coins')
    } else if (res.length < 10) {
        // for less than 10 results
        embed.setColor('#00BFFF')
        for (i = 0; i < res.length; i++) {
            let member = message.guild.members.get(res[i].UserID) || 'User left guild'

            if (member === 'User left guild') {
                embed.addField(`${i + 1}. ${member}`, `**Coins**: ${res[i].Coins}`)
            } else {
                embed.addField(`${i + 1}. ${member.user.username}`, `**Coins**: ${res[i].Coins}`)
            }
        }
    } else {
        // for more than 10 results
        embed.setColor('#00BFFF')
        for (i = 0; i < 10; i++) {
            let member = message.guild.members.get(res[i].UserID) || 'User left guild'

            if (member === 'User left guild') {
                embed.addField(`${i + 1}. ${member}`, `**Coins**: ${res[i].Coins}`)
            } else {
                embed.addField(`${i + 1}. ${member.user.username}`, `**Coins**: ${res[i].Coins}`)
            }
        }
    }

    message.channe.send(embed)
})

0 个答案:

没有答案