我想做一些事情来防止整个消息没有被发送,就像机器人在没有成功发送所述消息的情况下抛出错误一样。
假设信息是:
Hello world, I am Johnty *1000+ more chars here*
我希望它能够做到:
Hello world, I am Johnty *500+ more chars here*...
const embed = new Discord.MessageEmbed()
.setDescription(`${message.content}`);
这很简单,直到Plexi Development的一位同事向我展示了如何。
谢谢猫真棒#3153
代码:
const trim = (str, max) => (str.length > max ? `${str.slice(0, max - 3)}...` : str);
用法:
const Discord = require("discord.js");
const trim = (str, max) => (str.length > max ? `${str.slice(0, max - 3)}...` : str);
const embed = new Discord.MessageEmbed()
.setDescription(`${trim(message.content, 500)}`);
message.channel.send(embed);