简体   繁体   English

使用 quick.db 设置描述

[英]Setting a description with quick.db

In my discord bot, I want all users to have a customizable profile.在我的 discord 机器人中,我希望所有用户都有一个可自定义的配置文件。 Whenever they run a command,profile or,p.每当他们运行命令,配置文件或,p。 the bot will display an embed with bio (which is like an introduction like "Hello World" or something), custom embed color of their choice and other database information (.ie coins. energy etc,), I want to make sure that whenever they run something like,desc Hello World.该机器人将显示一个嵌入生物(就像“Hello World”之类的介绍)、他们选择的自定义嵌入颜色和其他数据库信息(即硬币、能量等),我想确保无论何时他们运行类似,desc Hello World。 their profile embed will have the message Hello World.他们的个人资料嵌入将包含消息 Hello World。 and if they run.desc Lorem another time.如果他们再次运行.desc Lorem。 their custom embed's bio will be edited to Lorem and so on.他们的自定义嵌入的生物将被编辑为 Lorem 等等。 I got them implement with simple db.get and db.set function using quick.db but the problem is whenever the user sets a description with more than one arguments like Hello World , it only appears on the embed as HelloWorld but not the actual correct one with spaces.我使用 quick.db 用简单的 db.get 和 db.set function 实现了它们,但问题是每当用户使用多个 arguments (如Hello World )设置描述时,它只会在嵌入中显示为HelloWorld而不是实际正确的一个带空格。 I really want the embed to display exactly what the user sets its description (with spaces and stuffs ) but currently my code isn't capable of it.我真的希望嵌入能够准确显示用户设置其描述的内容(带有空格和内容),但目前我的代码无法做到这一点。 Please give it a look and point out where I should change!请看一下并指出我应该改变的地方!

const db = require("quick.db");
const Discord = require("discord.js");

module.exports = {
  commands: ["description", "desc"],
  minArgs: 1,
  maxArgs: null,
  expectedArgs: ["description to add"],

  callback: (message, arguments, text) => {
    var desc;
    desc = arguments.join("");
    let tester = db.get(`_desc${message.author.id}`);

    if (!tester) {
      db.set(`_desc${message.author.id}`, desc);
    } else {
      db.delete(`_desc${message.author.id}`), db.set(`_desc${message.author.id}`, desc);
    }
    console.log(desc);
  },
};

The above is the code for.desc and the below is the one for !profile.上面是.desc 的代码,下面是!profile 的代码。

const db = require("quick.db");
const Discord = require("discord.js");

module.exports = {
  commands: ["profile", "p"],
  alias: ["p"],
  minArgs: 0,
  maxArgs: null,

  callback: async (message, arguments, text) => {
    let target = message.mentions.members.first() || message.author;

    const balance = db.get(`honey_${target.id}`);
    const energy = db.get(`energy_${target.id}`);
    var desc = db.get(`_desc${target.id}`);
    if (desc === null) {
      let desc = "this user have yet to set a description!";
    }

    const embed = new Discord.MessageEmbed()
      .setTitle(`${target.tag}'s profile`)
      .setColor("#ECB802")
      .addFields(
        { name: "Description", value: `${desc}`, inline: false },
        {
          name: "cards",
          value: "1",
          inline: true,
          //to do
        },
        { name: "Gym battle record", value: "1/0", inline: true }, //to do
        {
          name: "Honey",
          value: `${balance} :honey_pot:`,
          inline: true,
        },
        {
          name: "energy",
          value: `${energy} :dizzy:`,
          inline: true,
        },
      );

    message.channel.send(embed);
  },
};

You're using arguments.join('') to get the description, which will join two strings with an empty string:您正在使用arguments.join('')来获取描述,它将用空字符串连接两个字符串:

 const message = ['Hello', 'World']; console.log(message.join('')); // no spaces console.log(message.join(' ')); // instead, join by a space!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM