我试图分割消息时,它超过2000个字符,但在我更新discord.js到13.1我不能再这样做了
message.channel.send(code, { split: true, code: "js" })
what I try
message.channel.send({
content: Util.splitMessage(code)
})
// let {Util} = require("discord.js")
您必须在SplitOptions
.中传递一个字符作为分隔符。
在指定的字符处将字符串拆分为多个块不超过特定长度。(
Util.splitMessage()
)
老实说,我觉得这个方法的设计有点奇怪。虽然要将字符串分割的字符是必要的,但char
参数本身是可选的。更奇怪的是你在发送消息时没有得到错误>2000个字符,但是当使用Util-方法时。
const {
Util: { splitMessage },
} = require("discord.js");
const split = splitMessage("test".repeat(255) + "x" + "test".repeat(250), {
char: "x",
}); // => ["test"*255, the other 255 "test"]
我想你正在寻找一种方法来自动缩短消息时,它超过2000
字符的限制。恐怕以后你得开始为这类事情构建自己的辅助函数了。
此功能现在必须手动处理,例如通过Formatters。coblock和Util。splitMessage帮手。
发送消息、嵌入、文件等
幸运的是,它非常直接:
const customSplitMessage = (text) => [
text.substring(0, 2000),
text.substring(2000, text.length),
];
然后像这样使用:
message.channel.send({
content: customSplitMessage("test".repeat(501))[0],
}); // => sends the first exactly 2000 chars