【问题标题】:showing guild name & people requested the commands显示公会名称和请求命令的人
【发布时间】:2020-06-29 14:22:42
【问题描述】:

我正在尝试显示公会的名称和请求命令的人。 我已经尝试过${message.guild.name} & $(message.author),但没有成功

这是我的代码

const embed = new Discord.MessageEmbed()
                            .setColor('BLUE')
                            .setAuthor(' ${message.guild.name} Help Menu', message.guild.iconURL({ dynamic: true }))
                            .setThumbnail(client.user.avatarURL())
                            .addField('All',"`ping`,`commands`,`commands`,`web`,`repost`,`help`")
                            .setFooter('Use % prefix in every command.More commands coming soon. Requested by $(message.author)', message.author.displayAvatarURL({ dynamic: true }))
                            
                            .setTimestamp()

【问题讨论】:

    标签: node.js discord.js


    【解决方案1】:

    您需要使用重音符号(``)${} 以确保变量被视为变量。

    错误: .setAuthor('${message.guild.name}

    右: .setAuthor(`${message.guild.name}

    ` 和 ' 非常不同,请注意这一点。

    const embed = new Discord.MessageEmbed()
      .setColor('BLUE')
      .setAuthor(`${message.guild.name} Help Menu`, message.guild.iconURL({ dynamic: true }))
      .setThumbnail(client.user.avatarURL())                           
      .addField('All',"`ping`,`commands`,`commands`,`web`,`repost`,`help`")
      .setFooter(`Use % prefix in every command. More commands coming soon. Requested by 
      ${message.author}`, message.author.displayAvatarURL({ dynamic: true }))
      .setTimestamp()
    

    【讨论】:

      【解决方案2】:

      ${} 是一个模板字符串。如您所见here,您需要使用重音符号 (`),而不是引号。

      您在setFooter 函数中又犯了一个错误。您使用了圆括号而不是大括号。

      const embed = new discord.MessageEmbed()
          .setColor('BLUE')
          .setAuthor(`${message.guild.name} Help Menu`, message.guild.iconURL({ dynamic: true }))
          .setThumbnail(client.user.avatarURL())
          .addField('All',"`ping`,`commands`,`commands`,`web`,`repost`,`help`")
          .setFooter(`Use % prefix in every command.More commands coming soon. Requested by ${message.author.tag}`, message.author.displayAvatarURL({ dynamic: true }))
          
          .setTimestamp()
      

      【讨论】:

        猜你喜欢
        • 2021-10-14
        • 2021-10-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-01-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多