You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何实现支持自定义颜色的Discord通用Embed自定义命令?

通用自定义Embed命令实现方案

完全可行,针对你的需求,结合你正在使用的工具,这里提供具体实现方案:

一、用Dyno Bot快速实现

Dyno的自定义命令功能可以直接满足需求,无需写代码:

  • 步骤:
    1. 进入Dyno控制面板的「Custom Commands」页面
    2. 创建新命令(比如命名为!embed)
    3. 命令内容填写以下Dyno Embed模板:
      {{embed
        "description": "{{args.1}}",
        "color": "{{args.2}}"
      }}
      
    4. 设置命令使用格式为!embed <内容> <颜色代码>,比如用户输入!embed 这是一条测试消息 #FF5733,就会发送橙色的Embed消息。
  • 优化点:如果用户忘记输入颜色,可以给颜色字段加默认值,比如把"color"改为"{{args.2 || '#3498db'}}",这样默认用蓝色。

二、用Sapphire框架实现(更灵活可控)

如果需要更高的自定义度,用Sapphire写代码实现是更好的选择,以下是两种常见的命令类型示例:

前缀命令(适合习惯输入前缀的用户)

const { Command } = require('@sapphire/framework');

class CustomEmbedCommand extends Command {
  constructor(context) {
    super(context, {
      name: 'embed',
      description: '发送自定义内容和颜色的Embed',
      args: [
        {
          name: 'content',
          required: true,
          match: 'rest' // 把空格后的所有内容作为消息体
        },
        {
          name: 'color',
          required: false,
          defaultValue: '#3498db' // 默认蓝色
        }
      ]
    });
  }

  async messageRun(message, args) {
    const content = await args.rest('string');
    const color = await args.pick('string').catch(() => this.options.args[1].defaultValue);
    
    const embed = this.container.client.embed()
      .setDescription(content)
      .setColor(color);
    
    return message.channel.send({ embeds: [embed] });
  }
}

module.exports = { CustomEmbedCommand };

Slash命令(符合Discord官方交互规范)

const { SlashCommandBuilder } = require('@discordjs/builders');
const { Command } = require('@sapphire/framework');

class EmbedSlashCommand extends Command {
  constructor(context) {
    super(context, {
      name: 'embed',
      description: '发送自定义内容和颜色的Embed'
    });
  }

  registerApplicationCommands(registry) {
    registry.registerChatInputCommand(
      new SlashCommandBuilder()
        .setName(this.name)
        .setDescription(this.description)
        .addStringOption(opt =>
          opt.setName('content')
            .setDescription('Embed里的内容')
            .setRequired(true))
        .addStringOption(opt =>
          opt.setName('color')
            .setDescription('Embed颜色(十六进制代码,如#FF0000)')
            .setRequired(false))
    );
  }

  async chatInputRun(interaction) {
    const content = interaction.options.getString('content');
    const color = interaction.options.getString('color') || '#3498db';
    
    const embed = this.container.client.embed()
      .setDescription(content)
      .setColor(color);
    
    return interaction.reply({ embeds: [embed] });
  }
}

module.exports = { EmbedSlashCommand };

三、可选工具推荐

如果不想写代码,YAGPDB.xyz也是不错的选择,它的自定义命令系统支持参数解析和Embed生成,免费版就能支持大量用户,语法简单易上手。

内容的提问来源于stack exchange,提问作者Sayuri

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.11 20:12:35