[text]
与[username]
组合在一起(您可以将任何用户名放在“ realdonaldtrump
”处,之后的任何内容都是实际的消息。
我尝试了很多事情,唯一要做的就是让王牌成为默认推文,并且无法对其进行更改,因此它本来是>tweet [message]
而不是>tweet [username] [message]
,但是我想要自定义用户名。有关如何从[username]
删除[text]
这是代码
exports.exec = async (client, message, args, level, settings, texts) => {
const user = args[0];
// Fires Error message that the command wasn't ran correctly.
if (!user) {
return client.emit('commandUsage', message, this.help);
}
// Fires Error message that the command wasn't ran correctly.
const text = args.join(" ");
// Below is a self-deletion message prior to image sending when it's fetching the actual image.
message.channel.send({
embed: {
color: 0,
description: `${message.author} Generating image.`
}
}).then(msg => {
msg.delete(5000).catch(() => { });
}).catch(e => {
});
// Above is a self-deletion message prior to image sending when it's fetching the actual image.
try {
const { body } = await snekfetch.get(`https://nekobot.xyz/api/imagegen?type=${user.toLowerCase() === "realdonaldtrump" ? "trumptweet" : "tweet"}&username=${user.startsWith("@") ? user.slice(1) : user}&text=${encodeURIComponent(text)}`);
message.channel.send("", { file: body.message });
// Below is a automatic logger
} catch (err) {
const errorlogs = client.channels.get('480735959944527886')
const embed = new discord.RichEmbed()
.setAuthor("ERROR", "https://i.imgur.com/Omg7uJV.png")
.setDescription(`${message.author} An error has occured using this command, this has automatically be logged and sent to ${client.channels.get('480735959944527886')} to be reviewed.`)
.setColor(0)
.setTimestamp()
message.channel.send({ embed });
errorlogs.send(`Error with \`$tweet\` command!\n\nError:\n\n ${err}`)
}
// Above is a automatic logger
};
答案 0 :(得分:3)
您正在串联args
来设置text
变量
const text = args.join(" ");
但是在您的示例中,args
的值为["realdonaltrump", "yeeet"]
,因此导致text
的值为"realdonaldtrump yeet"
。
就像您对user
变量所做的那样:
const text = args[1]
您可能需要验证参数的值。
答案 1 :(得分:0)
您可以使用string.replace
方法,它将用所有内容替换用户名:
const text = args.join(" ").replace(new RegExp(`${user}`), "")
希望有帮助!