因此,每当执行的计算结果的输出超过4096个字符时,我的Bot就发送一个文件(因为这是当前不一致描述的限制),但是,每次我试图让Bot发送有问题的文件时,总是会出现以下错误:
DiscordAPIError: Invalid Form Body
embeds: Embed size exceeds maximum size of 6000
“守则”如下:
const Discord = require('discord.js');
const { inspect } = require('util');
module.exports = {
name: 'eval',
description: 'Evaluates JavaScript Code.',
usage: 'ds!eval <code>',
run: async(client, msg, args) => {
try{
const command = args.join(' ');
if (msg.author.id !== '705557092802625576') {
msg.channel.send('You are not the Bot Owner!');
return;
}
if (args.length < 1) {
msg.channel.send('You need to provide some code!');
return;
}
if (command.includes('client.token') || command.includes('process.env.TOKEN')) {
msg.channel.send('You cannot execute commands containing .token!');
return;
}
const evaled = eval(command);
const type = typeof evaled;
const typeCapitalized = type.charAt(0).toUpperCase() + type.slice(1);
// if the output exceeds 4096 characters, create a hastebin
if (eval(command).toLocaleString().length > 4096) {
const file = new Discord.MessageAttachment(`${type}_output.txt`, 'eval_output.txt');
return msg.reply(`Output is too large to send.`, {files: [file]});
}
const embed = new Discord.MessageEmbed()
.setColor('BLUE')
.setThumbnail(client.user.displayAvatarURL({dynamic: true}))
.setAuthor({ name: `${msg.author.tag}`, iconURL: msg.author.displayAvatarURL({dynamic: true})})
.setTitle('Evaluated Code')
.setDescription(`**Output:**\`\`\`js\n${inspect(evaled,{ depth : 2 })}\`\`\`\n**Input:** \`\`\`js\n${command}\n\`\`\``)
.addFields(
{
name: 'Type:',
value: `\`\`\`js\n${typeCapitalized}\n\`\`\``,
inline: false
},
{
name: "Time:",
value: `\`\`\`js\n${Date.now() - msg.createdTimestamp}ms\n\`\`\``,
inline: false
}
)
.setTimestamp();
return msg.reply({embeds: [embed]});
} catch(error) {
console.log(error);
const embed = new Discord.MessageEmbed()
.setAuthor({ name: `${msg.author.tag}`, iconURL: msg.author.displayAvatarURL({dynamic: true})})
.setColor('RED')
.setTitle('Error ocurred!')
.setDescription(`\`\`\`js\n${error.stack}\n\`\`\``)
.setTimestamp();
return msg.reply({embeds: [embed]});
}
}
};
发布于 2022-05-02 08:01:31
您想要发送的嵌入量太大了,正如错误说的:嵌入大小超过6000的最大大小也要记住,标题、作者、描述和所有字段一起不能超过6000个字符,因为这是对每个嵌入(不是每个字段/描述)的限制。
发布于 2022-05-18 13:36:30
好吧,我自己修了密码。这是一个新的:
const Discord = require('discord.js');
const { inspect } = require('util');
const Buffer = require('buffer').Buffer;
module.exports = {
name: 'eval',
description: 'Evaluates JavaScript Code.',
usage: 'ds!eval <code>',
run: async (client, msg, args) => {
try {
const command = args.join(' ');
if (msg.author.id !== '705557092802625576') {
msg.channel.send('You are not the Bot Owner!');
return;
}
if (args.length < 1) {
msg.channel.send('You need to provide some code!');
return;
}
if (command.includes('.token') || command.includes('.TOKEN')) {
msg.channel.send('You cannot execute commands containing .token!');
return;
}
const evaled = eval(command);
const type = typeof evaled;
const typeCapitalized = type.charAt(0).toUpperCase() + type.slice(1);
const embed = new Discord.MessageEmbed()
embed.setDescription(`**Output:**\`\`\`js\n${inspect(evaled, { depth: 2 })}\`\`\`\n**Input:** \`\`\`js\n${command}\n\`\`\``)
if (embed.description.length > 4096) {
embed.setColor('BLUE')
embed.setThumbnail(client.user.displayAvatarURL({ dynamic: true }))
embed.setAuthor({ name: `${msg.author.tag}`, iconURL: msg.author.displayAvatarURL({ dynamic: true }) })
embed.setTitle('Evaluated Code')
embed.setDescription(`**Input:** \`\`\`js\n${command}\n\`\`\``)
embed.addFields(
{ name: 'Type:', value: `\`\`\`js\n${typeCapitalized}\n\`\`\``, inline: false }, { name: "Time:", value: `\`\`\`js\n${Date.now() - msg.createdTimestamp}ms\n\`\`\``, inline: false })
embed.setTimestamp()
const file = Buffer.from(inspect(evaled, { depth: 2 }));
return msg.reply({ embeds: [embed], files: [{ attachment: file, name: 'output.js' }] });
} else {
const embed2 = new Discord.MessageEmbed()
.setColor('BLUE')
.setThumbnail(client.user.displayAvatarURL({ dynamic: true }))
.setAuthor({ name: `${msg.author.tag}`, iconURL: msg.author.displayAvatarURL({ dynamic: true }) })
.setDescription(`**Output:**\`\`\`js\n${inspect(evaled, { depth: 2 })}\`\`\`\n**Input:** \`\`\`js\n${command}\n\`\`\``)
.setTitle('Evaluated Code')
.addFields(
{ name: 'Type:', value: `\`\`\`js\n${typeCapitalized}\n\`\`\``, inline: false }, { name: "Time:", value: `\`\`\`js\n${Date.now() - msg.createdTimestamp}ms\n\`\`\``, inline: false })
.setTimestamp()
return msg.reply({ embeds: [embed2] });
}
} catch (error) {
console.log(error);
const embed = new Discord.MessageEmbed()
.setAuthor({ name: `${msg.author.tag}`, iconURL: msg.author.displayAvatarURL({ dynamic: true }) })
.setColor('RED')
.setTitle('Error ocurred!')
.setDescription(`\`\`\`js\n${error.stack}\n\`\`\``)
.setTimestamp();
return msg.reply({ embeds: [embed] });
}
}
};
https://stackoverflow.com/questions/72016176
复制