【问题标题】:Can users themselves set a description for their RichEmbed用户自己可以为他们的 RichEmbed 设置描述吗
【发布时间】:2018-12-03 06:23:12
【问题描述】:

我正在使用 discord.js 开发一个不和谐机器人。有了我的机器人,用户就有了自己的个人资料。所以他们去 !profile @me 并且他们的个人资料出现了。我想知道用户是否有办法使用命令,比如“!setDescription I like Discord”。当他们使用命令查看他们的个人资料“!profile @me”时,他们的个人资料嵌入将有他们写的描述,这可能吗?如果是这样,我怎么能把它合并到我的代码中? 提前感谢您的帮助!

【问题讨论】:

    标签: javascript discord.js


    【解决方案1】:

    您可以存储它们的描述,然后在以后重复使用:

    当用户运行!setDescription I like Discord 时,您将I like Discord 保存在这样的对象中

    //the user is stored as "message.author"
    //the argument "I like Discord" is stored as "text"
    var desc = {};
    desc[message.author.id] = text; //desc -> {"id": "I like Discord"}
    

    当用户运行!profile @me 时,您使用您的desc 对象来获取他们的描述

    //the user is stored as "message.author"
    embed.setDescription(desc[message.author.id]);
    

    请记住,如果您将数据保存到变量中,当您关闭它时,所有描述都将丢失。为避免这种情况,您可以将对象保存到 JSON 文件或您喜欢的任何位置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-25
      相关资源
      最近更新 更多