首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >DiscordAPIError:无效表单主体3.options[1].type:此字段是必需的

DiscordAPIError:无效表单主体3.options[1].type:此字段是必需的
EN

Stack Overflow用户
提问于 2022-02-22 20:51:51
回答 1查看 1.8K关注 0票数 0

因此,我有刚才发出的锁定命令,但是当我想启动bot时,我会得到以下错误

代码语言:javascript
复制
DiscordAPIError: Invalid Form Body
3.options[1].type: This field is required

我试着修理它,但我不知道问题出在哪里。

它由4个文件组成。

文件1: GiveawaySys.js <--系统文件

代码语言:javascript
复制
const { GiveawaysManager } = require('discord-giveaways');
const giveawayModel = require("../Structures/Schemas/GiveawayDB");

module.exports = (client) => {
    const GiveawayManagerWithOwnDatabase = class extends GiveawaysManager {
        async getAllGiveaways() {
            return await giveawayModel.find().lean().exec();
        }
    
        async saveGiveaway(messageId, giveawayData) {
            await giveawayModel.create(giveawayData);
            return true;
        }
    
        async editGiveaway(messageId, giveawayData) {
            await giveawayModel.updateOne({ messageId }, giveawayData, { omitUndefined: true }).exec();
            return true;
        }
    
        async deleteGiveaway(messageId) {
            await giveawayModel.deleteOne({ messageId }).exec();
            return true;
        }
    };
    
    const manager = new GiveawayManagerWithOwnDatabase(client, {
        default: {
            botsCanWin: false,
            embedColor: '#FF0000',
            embedColorEnd: '#000000',
            reaction: ''
        }
    });
    client.giveawaysManager = manager;
}

文件2: Lockdown.js <-架构

代码语言:javascript
复制
const { model, Schema } = require("mongoose");

module.exports = model("Lockdown", new Schema({
    GuildID: String,
    ChannelID: String,
    Time: String,
})
);

文件3: lock.js <- lock命令

代码语言:javascript
复制
const {
    CommandInteraction,
    MessageEmbed
} = require("discord.js");
const DB = require("../../Structures/Schemas/LockDown");
const ms = require("ms");

module.exports = {
    name: "lock",
    description: "Lockdown this channel",
    permission: "MANAGE_CHANNELS",
    options: [{
            name: "time",
            description: "Expire date for this lockdown (1m, 1h, 1d)",
            type: "STRING",
        },
        {
            name: "reason",
            description: "Provide a reason for this lockdown.",
            tyoe: "STRING",
        },
    ],
    /**
     * 
     * @param {CommandInteraction} interaction 
     */
    async execute(interaction) {
        const {
            guild,
            channel,
            options
        } = interaction;

        const Reason = options.getString("reason") || "no specified reason";

        const Embed = new MessageEmbed();

        if (!channel.permissionsFor(guild.id).has("SEND_MESSAGES"))
            return interaction.reply({
                embeds: [Embed.setColor("RED").
                    setDescription("⛔  | This channel is already locked."),
                ],
                ephemeral: true,
            });

        channel.permissionOverwrites.edit(guild.id, {
            SEND_MESSAGES: false,
        });
        interaction.reply({
            embeds: [Embed
                .setColor("RED")
                .setDescription(` | This channel is now under lockdown for: ${Reason}`
                ),
            ],
        });
        const Time = options.getString("time");
        if (Time) {
            const ExpireDate = Date.now() + ms(Time);
            DB.create({
                GuildID: guild.id,
                ChannelID: channel.id,
                Time: ExpireDate
            });

            setTimeout(async () => {
                channel.permissionOverwrites.edit(guild.id, {
                    SEND_MESSAGES: null,
                });
                interaction.editReply({
                        embeds: [Embed
                            .setDescription(" | The lockdown has been lifted")
                            .setColor("GREEN")
                        ],
                    })
                    .catch(() => {});
                await DB.deleteOne({
                    ChannelID: channel.id
                });
            }, ms(Time));
        }

    },
};

文件4: unlock.js <--解锁命令

代码语言:javascript
复制
const {
    CommandInteraction,
    MessageEmbed
} = require("discord.js");
const DB = require("../../Structures/Schemas/LockDown");

module.exports = {
    name: "unlock",
    description: "Lift a lockdown from a channel",
    permission: "MANAGE_CHANNELS",
    /**
     * 
     * @param {CommandInteraction} interaction 
     */
    async execute(interaction) {
        const {
            guild,
            channel
        } = interaction;

        const Embed = new MessageEmbed();

        if (channel.permissionsFor(guild.id).has("SEND_MESSAGES"))
            return interaction.reply({
                embeds: [Embed
                    .setColor("RED")
                    .setDescription("⛔ | This channel is not locked"),
                ],
                ephemeral: true,
            });

        channel.permissionOverwrites.edit(guild.id, {
            SEND_MESSAGES: null,
        });

        await DB.deleteOne({
            ChannelID: channel.id
        });

        interaction.reply({
            embeds: [Embed
                .setColor("GREEN")
                .setDescription(" | Lockdown has been lifted."),
            ],
        });
    },
};

请帮我解决这个问题,我找不到这个问题

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-02-24 00:02:48

您所得到的错误(.options[1].type is required)是对问题所在的一个非常大的提示。在搜索文件的代码时,我在options[1]中的第三个文件中看到了这个

代码语言:javascript
复制
{
    name: "reason",
    description: "Provide a reason for this lockdown.",
    tyoe: "STRING",
}

注意到问题了吗?这是个错误。"tyoe"而不是"type",导致djs抱怨需要"type"

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71228140

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档