【发布时间】:2019-02-07 14:43:18
【问题描述】:
[text] 与[username] 结合使用(您可以将任何用户名放在“realdonaldtrump”所在的位置。之后的任何内容都是实际消息。
我已经尝试了很多东西,我唯一需要做的就是让 trump 成为默认推文并且无法更改它,所以它应该是 >tweet [message] 而不是 >tweet [username] [message] 但我想要拥有自定义用户名。有关如何从 [text] 中删除 [username] 的任何线索
这是代码
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
};
【问题讨论】:
-
你能告诉我们整个代码吗?您正在使用等待,但异步部分是什么?
-
对此表示歉意,重新编辑代码块以包含除导出选项外的整个代码,因为它们都可以工作:)
标签: javascript bots discord