【问题标题】:Discord.js V13 TypeError: (intermediate value).setName(...).setDescription(...).addAttachmentOption is not a functionDiscord.js V13 TypeError: (中间值).setName(...).setDescription(...).addAttachmentOption 不是函数
【发布时间】:2023-01-05 04:43:43
【问题描述】:
const { SlashCommandBuilder } = require('@discordjs/builders');
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');

const data = new SlashCommandBuilder()
    .setName('test')
    .setDescription('test')
    .addAttachmentOption(option =>
        option.setName('img')
            .setDescription('the image')
    )
            

const rest = new REST({ version: '9' }).setToken("token");

rest.put(Routes.applicationGuildCommands("id", "id"), { body: data })
    .then(() => console.log('Successfully registered application commands.'))
    .catch(console.error);

得到 TypeError: (intermediate value).setName(...).setDescription(...).addAttachmentOption is not a function error idk 为什么

【问题讨论】:

  • 你有哪个版本的discord.js
  • 您确切的 discord.js npm list discord.js 和 node node -v 版本是什么?

标签: node.js discord.js


【解决方案1】:
const { SlashCommandBuilder } = require('@discordjs/builders');
const { REST, Routes } = require("discord.js");
const config = require("./config.json")

const commands = [];

commands.push(
    new SlashCommandBuilder()
    .setName('test')
    .setDescription('test')
    .addAttachmentOption(option =>
        option.setName('img')
            .setDescription('the image')
    )
)


const rest = new REST({ version: '9' }).setToken(config.token);

rest.put(Routes.applicationGuildCommands("675372434446352426", "724845607768031232"), { body: commands })
    .then(() => console.log('Successfully registered application commands.'))
    .catch(console.error);

这对我有用,不确定 @discordjs/rest 是什么,但不需要它,因为可以直接从 discord.js 获取 REST 对象,确保删除 const { REST } = require('@discordjs/rest'); const { Routes } = require('discord-api-types/v9');,因为它们不需要。

【讨论】:

    猜你喜欢
    • 2022-07-22
    • 1970-01-01
    • 2022-01-17
    • 2023-01-16
    • 2019-08-30
    • 1970-01-01
    • 2021-01-13
    • 2018-02-10
    • 2022-11-04
    相关资源
    最近更新 更多