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

Discord.js v13.2发送带按钮的消息按钮不显示如何解决

你代码的核心问题是 Discord.js v13 中TextBasedChannel.send()方法的传参格式不符合规范,且按钮组件必须被MessageActionRow容器包裹才能发送。

修复步骤
  • 首先需要从discord.js包中导入MessageActionRow类,该类是交互组件的标准容器
  • 将创建好的MessageButton实例添加到MessageActionRow的组件列表中
  • 调整send方法的入参为单个配置对象,文本内容放入content字段,组件数组放入components字段
修复后完整代码
// 注意顶部要同时导入所需的类
const { Client, Intents, MessageButton, MessageActionRow } = require('discord.js');

client.once("ready", async () => {
  const button = new MessageButton()
    .setLabel("Go To Site")
    .setStyle("PRIMARY") // v13中蓝色样式官方枚举为PRIMARY,写"blue"也可兼容但推荐用枚举值
    .setCustomId("btn-go-to-site");

  // 将按钮放入ActionRow容器
  const actionRow = new MessageActionRow()
    .addComponents(button);

  const helpChannel = await client.channels.fetch(channelID);
  // 统一传参为配置对象
  helpChannel.send({
    content: 'Welcome to Site',
    components: [actionRow]
  });
});
额外说明
  • 单个MessageActionRow最多可放置5个按钮,单条消息最多可放置5个MessageActionRow
  • 如果你需要做跳转外链的按钮,无需设置CustomId,替换为调用setURL('你的外链地址')即可
  • 请确保客户端初始化时已经开启了消息发送相关的必要权限和意图

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.29 11:57:02