【问题标题】:Username in embed footer discord bot嵌入页脚不和谐机器人中的用户名
【发布时间】:2021-06-02 01:06:56
【问题描述】:

我希望请求命令的用户的用户名显示在页脚中。我尝试了很多事情,但我不知道我应该怎么做。 我的代码在这里:

const exampleEmbed = new Discord.MessageEmbed()

.setColor('#000033')
.setTitle('```Help```')
.setDescription('For more help, type .help (command)')
.addFields(
    { name: '.list', value: 'Opens list of all the achievements' },
    { name: '.profile', value: 'Opens achievement statistics from a member', },
    { name: '.leaderbord', value: 'Opens a leaderbord of the members with most achievements', },
    { name: '.bot', value: 'Opens bot links and information about the bot', },
    { name: '.setup', value: 'Starts the setup of the bot (only for administrators)', }
)
.setTimestamp()
.setFooter("here should the name stand")

    client.on("message", (message) => {
        if (message.content == ".help") {
            message.channel.send(exampleEmbed)
            console.log(message.member.user.tag +' executed command .HELP')
        }
    })

【问题讨论】:

    标签: javascript discord discord.js bots


    【解决方案1】:

    您正在寻找.setFooter(message.author.username)

    完整代码:

        client.on("message", (message) => {
            if (message.content == ".help") {
                 const exampleEmbed = new Discord.MessageEmbed()
                   .setColor('#000033')
                   .setTitle('```Help```')
                   .setDescription('For more help, type .help (command)')
                   .addFields(
                      { name: '.list', value: 'Opens list of all the achievements' },
                      { name: '.profile', value: 'Opens achievement statistics from a member', },
                      { name: '.leaderbord', value: 'Opens a leaderbord of the members with most achievements', },
                      { name: '.bot', value: 'Opens bot links and information about the bot', },
                      { name: '.setup', value: 'Starts the setup of the bot (only for administrators)', }
                   )
                   .setTimestamp()
                   .setFooter(message.author.username);
    
                message.channel.send(exampleEmbed)
                console.log(message.member.user.tag +' executed command .HELP')
            }
        })
    

    如下所述,您需要将嵌入放在消息事件侦听器中

    【讨论】:

    • 如果我这样做,当我在 PowerShell 中启动它时会弹出错误引用错误,消息未定义
    • @hubschrauber 最好将您的嵌入in messageEvent,因为您想使用未在 messageEvent 之外定义的message
    猜你喜欢
    • 2020-12-25
    • 2017-10-08
    • 2019-04-11
    • 1970-01-01
    • 2021-01-21
    • 1970-01-01
    • 2021-12-21
    • 2018-03-20
    • 2021-04-14
    相关资源
    最近更新 更多