gpt4 book ai didi

javascript - ValidationError > s.string 应为接收到的字符串原语 : | undefined

转载 作者:行者123 更新时间:2023-12-05 03:20:00 29 4
gpt4 key购买 nike

我使用 discord js 为我的服务器制作一个多用途的 discord 机器人,但它给了我这个错误:

ValidationError: Expected a string primitive

昨天工作正常,但我忘记保存一些东西,我不知道是什么。

const fs = require('node:fs');
const path = require('node:path');
const {
Client,
GatewayIntentBits,
Partials,
Collection,
} = require("discord.js");

const { Player } = require('discord-player');
const { Routes } = require('discord-api-types/v10');
const { token, prefix, guildId, clientId } = require('./config.json');
const { REST } = require('@discordjs/rest');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildPresences,
GatewayIntentBits.GuildVoiceStates
],
partials: [
Partials.Channel,
Partials.Message,
Partials.User,
Partials.GuildMember,
],
});

client.player = new Player(client, {
ytdlOptions: {
quality: "highestaudio",
highWaterMark: 1 << 25
}
});

module.exports = client;

// command handler

//slash commands
const slashCommands = [];
client.slashCommands = new Collection();

const commandsPath = path.join(__dirname, "commands"); // E:\yt\discord bot\js\intro\commands
const slash_commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('S.js'));
for(const file of slash_commandFiles)
{
const filePath = path.join(commandsPath, file);
const command = require(filePath);

client.slashCommands.set(command.data.name, command);
slashCommands.push(command.toJSON());
}

console.log(slashCommands);

//message commands
client.messageCommands = new Collection();
const message_commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('M.js'));
for (const file of message_commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
// Set a new item in the Collection
// With the key as the command name and the value as the exported module
client.messageCommands.set(command.Name, command);
}

//event handler
const eventsPath = path.join(__dirname, 'events');
const eventFiles = fs.readdirSync(eventsPath).filter(file => file.endsWith('.js'));

for (const file of eventFiles) {
const filePath = path.join(eventsPath, file);
const event = require(filePath);
if (event.once) {
client.once(event.name, (...args) => event.execute(...args));
} else {
client.on(event.name, (...args) => event.execute(...args));
}
}

// messageCommand handler

client.on('messageCreate', (message) => {
const args = message.content.slice(prefix.length).split(' ');
const command = args[0];
if (client.messageCommands.get(command)) {
let Command = client.messageCommands.get(command);
Command.execute(message);
}
});

client.on('ready', () => {
const rest = new REST({ version: '9' }).setToken(token);
rest.put(Routes.applicationGuildCommands(clientId, guildId),
{ body: slashCommands })
.then(() => console.log('Successfully updated commands for guild ' + guildId))
.catch(console.error);
console.log('bot is online!');
client.user.setStatus('idle');
});
client.login(token);

我确信任何命令文件都没有问题,因为它昨天运行良好。此行 slashCommands.push(command.toJSON()); 中有 100% 个错误;但我似乎无法修复它。 command.toJSON() 控制台记录正常,但在尝试插入列表时出错

最佳答案

遇到同样的问题,结果选项(即 addUserOption)需要描述。重点是它确实令人困惑,因为在执行 command.data.toJSON() 时会出现此错误。如果您按照指南中的描述动态加载命令文件并遇到此问题,请尝试手动执行 require 以预先触发验证。

关于javascript - ValidationError > s.string 应为接收到的字符串原语 : | undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73302171/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com