【问题标题】:Disord.js buttons error (TypeError: INVALID_BUTTON_STYLE: An invalid button styles was provided)Discord.js 按钮错误(TypeError:INVALID BUTTON STYLE:提供了无效的按钮样式)
【发布时间】:2021-10-27 13:05:06
【问题描述】:

我尝试使用不和谐按钮。我正在编写一些代码并运行它。但这没有用 那是按钮样式代码中的错误。 我使用的是 discord.js 12-,并使用 discord-button 制作了按钮 我不知道如何解决这个问题。我该怎么办?

这是错误

the bot is online!
C:\Users\user\Downloads\bot\node_modules\discord-buttons\src\v12\Util.js:13
      throw new TypeError('INVALID_BUTTON_STYLE: An invalid button styles was provided');
            ^

TypeError: INVALID_BUTTON_STYLE: An invalid button styles was provided
    at resolveStyle (C:\Users\user\Downloads\bot\node_modules\discord-buttons\src\v12\Util.js:13:13)
    at MessageButton.setStyle (C:\Users\user\Downloads\bot\node_modules\discord-buttons\src\v12\Classes\MessageButton.js:31:13)
    at Client.<anonymous> (C:\Users\user\Downloads\bot\index.js:28:14)
    at Client.emit (node:events:394:28)
    at MessageCreateAction.handle ot(C:\Users\user\Downloads\bot\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
    at Object.module.exports [as MESSAGE_CREATE] (C:\Users\user\Downloads\bot\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
    at WebSocketManager.handlePacket ot(C:\Users\user\Downloads\bot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:384:31)
    at WebSocketShard.onPacket (C:\Users\user\Downloads\bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22)
    at WebSocketShard.onMessage ot(C:\Users\user\Downloads\bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10)
    at WebSocket.onMessage (C:\Users\user\Downloads\bot\node_modules\ws\lib\event-target.js:132:16)

这是我的代码

const { prefix, token } = require('./config.json');
const Discord = require("discord.js");
const client = new Discord.Client();
const Database = require("./Helpers/Database");
const { MessageButton } = require('discord-buttons')

.....

    let button1 = new MessageButton()
        .setLabel("test1")
        .setStyle('ORANGE')
        .setID("button1")
    let button2 = new MessageButton()
        .setStyle('BLURPLE')
        .setLabel("test2")
        .setID("button2")
    let button3 = new MessageButton()
        .setStyle('gray')
        .setLabel("test3")
        .setID("button3")

.....

    message.author.send({embed: embed, buttons: [button1, button2, button3]})

【问题讨论】:

标签: javascript node.js discord.js discord-buttons


【解决方案1】:

根据docs,他们使用带有“e”的灰色。不是'a'。容易纠正的简单错误

let button3 = new MessageButton()
  .setStyle('grey') //not 'gray'
  .setLabel("test3")
  .setID("button3")

注意:此软件包在 discord.js v13 版本中已弃用。还有一些其他的包,比如discord-reply,它们也被弃用了,因为 v13 支持按钮和回复。

【讨论】:

  • 我把灰色变成了灰色。但它没有用。我不能在 discord v12 中使用 discord-botton 吗?
  • 我认为它与 v13 不兼容
猜你喜欢
  • 1970-01-01
  • 2021-10-16
  • 1970-01-01
  • 1970-01-01
  • 2010-11-20
  • 2019-07-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多