【问题标题】:How mention on discord.js如何在 discord.js 上提及
【发布时间】:2022-01-21 04:45:27
【问题描述】:

请帮忙,如何在消息中提及用户?我在网上找不到答案。我的代码:

  const exampleeEmbedd = new MessageEmbed()
  .setColor('#53db56')
  .setTitle('  [????] Приветствуем нового путника!')
  .setDescription(' Приветствуем вас ' + /*MENTION*/ + '!\nДобро пожаловать на международный сервер режима Geopolitics. \nЗдесь вы можете присоеденится к существующему городу/государству, либо зарегистрировать свой город/государство.')
  .setURL('')
  .setAuthor('????Имперский Бот????', 'https://images-ext-2.discordapp.net/external/nWASMV-67mx7guRheeUpvyD_cb6X2NkxUMH4PtbweyA/%3Fsize%3D512/https/cdn.discordapp.com/avatars/916617120064884796/5028d4861b407575072686657b3c2e9a.png' )
  .setThumbnail(user.avatarURL())
  .addFields(
  )
  .setImage('')
  .setTimestamp()
  .setFooter('asdas', 'https://images-ext-2.discordapp.net/external/nWASMV-67mx7guRheeUpvyD_cb6X2NkxUMH4PtbweyA/%3Fsize%3D512/https/cdn.discordapp.com/avatars/916617120064884796/5028d4861b407575072686657b3c2e9a.png');
  mess.channel.send( { embeds: [exampleeEmbedd] } );

【问题讨论】:

    标签: javascript discord.js


    【解决方案1】:

    您需要使用${user} 字符串或${user.tag},这样您的机器人才会提及用户。

    确保您将let user = message.mentions.members.first() 置于嵌入上方

    例子:

       const exampleeEmbed = new MessageEmbed()
      .setTitle('an embed')
      .setDescription(`Hello ${user}!`)
      mess.channel.send({ embeds: exampleeEmbed });
    

    还要确保将您的消息附上``

    【讨论】:

    • 我相信在 v13 中你必须添加 .toString(),即使它正在被字符串化
    【解决方案2】:

    Discord.js 在解释为字符串时会自动为您转换提及。

    "Foo" + user + "Bar" 转换为 Foo<@!1234567890>Bar

    使用模板字符串:

    `Foo${user}Bar`
    

    如果您只有用户 ID,您可以手动执行此操作:

    "Foo<@!" + userId + ">Bar"
    // or
    `Foo<@!${userId}>Bar`
    

    确保userId 是一个字符串。

    【讨论】:

    • 非常感谢!!!
    猜你喜欢
    • 2021-05-12
    • 2021-08-02
    • 2020-03-04
    • 2020-09-13
    • 2021-09-14
    • 2021-04-26
    • 1970-01-01
    • 2020-09-06
    • 2021-03-05
    相关资源
    最近更新 更多