【问题标题】:Is there a way to get user information by pinging someone in Discord.js?有没有办法通过在 Discord.js 中 ping 某人来获取用户信息?
【发布时间】:2022-01-12 05:13:58
【问题描述】:

我的 discord.js 文件中有一个命令,允许用户使用 !vote @user 命令为某人投票。每当我打印出@user 时,我都会得到<@!user_id>。有没有办法将该值转换为可操作的东西,例如,获取@users 的用户名或在语音通话中将其静音,例如使用msg.user 时?

client.on('message', msg) {
   if (msg.content.startsWith('!')) {
      let command = msg.content.substring('!'.length);
      let ping = command.split(' ');

      if(command == 'vote') {
         // Convert <@!user_id> into a manipulatable user?
         let user_information = ping[1]
      }
    }
 }

【问题讨论】:

标签: javascript node.js discord discord.js


【解决方案1】:

你可以使用message.mentions.users

像这样:

const mention = message.mentions.users.first();

或者,如果您想要该会员,您可以使用message.mentions.members.first(),例如:

const mention = message.mentions.members.first();

如果你不想使用它,你可以使用discord.js's guide on parsing mentions

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-04
    • 2021-08-07
    • 1970-01-01
    • 2021-07-05
    • 2021-09-20
    • 2021-03-09
    相关资源
    最近更新 更多