【问题标题】:I want to tag users in a leaderboard, but instead it tags their id我想在排行榜中标记用户,但它标记了他们的 id
【发布时间】:2020-08-12 13:27:47
【问题描述】:

我正在尝试为我的不和谐机器人制作排行榜,到目前为止它可以工作,但是每当我想在嵌入中标记玩家时,它只会发送类似 的内容,而不是:@wex

这是我的代码:

if (message.content.startsWith(`${prefix}btop`)) {
  if (message.member.roles.cache.find(r => r.name === "Walls")) {
    var description = ""
    let all = `SELECT userid , points FROM bufferpoints ORDER BY points DESC LIMIT 10;`
    db.all(all, (err, row) => {
      if (err) throw err;
      const topembed = new Discord.MessageEmbed()
        .setColor('#FF760B')
        .setTitle(message.guild.name + "'s TOP Buffercheckers!")
        .setTimestamp()
      let i = 0;
      row.forEach(function(row) {
        i++;
        if (row.points === 0) {
          return;
        }
        description += ` ${i}. <@${row.userid}>` + `** - ${row.points}**\n`
      })

      topembed.setDescription(description)
      message.channel.send(topembed)
    })
  }
}

如果有人想知道,这就是我现在得到的结果

感谢您的帮助!

【问题讨论】:

  • 您在使用时获得的是用户 ID 而不是名称: ?也许数据中有 row.username 可以做你想做的事?
  • 也许您所指的属性用户 ID 是错误的 - 是否有用户名 row.username 属性?
  • @Andrew 只有 userid 是用户 id 和 points 是不言自明的
  • 看起来您需要查找名称。 GET/users/{user.id} 返回给定用户 ID 的用户对象。 (discordapp.com/developers/docs/resources/user)
  • @Andrew 你建议我使用他们的用户名吗?

标签: javascript discord leaderboard


【解决方案1】:

我设法解决了这个问题。当我保存用户 ID 时,我使用了message.author.id。我将其更改为message.author.toString()。 Bot 将数据保存为 ,然后在排行榜中标记用户。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-02
    • 1970-01-01
    • 2010-11-26
    • 2012-02-15
    • 2012-10-29
    相关资源
    最近更新 更多