TravBot-v3/src/commands/utility/translate.ts

36 lines
1.2 KiB
TypeScript
Raw Normal View History

import {Command, NamedCommand} from "../../core";
2021-04-08 11:37:49 +00:00
import translate from "translate-google";
export default new NamedCommand({
description: "Translates your input.",
usage: "<lang ID> <input>",
2021-04-10 13:34:55 +00:00
async run({send, message, channel, guild, author, member, client, args}) {
const lang = args[0];
const input = args.slice(1).join(" ");
translate(input, {
to: lang
})
2021-04-08 11:37:49 +00:00
.then((res) => {
2021-04-10 13:34:55 +00:00
send({
embed: {
title: "Translation",
fields: [
{
name: "Input",
value: `\`\`\`${input}\`\`\``
},
{
name: "Output",
value: `\`\`\`${res}\`\`\``
}
]
}
});
})
2021-04-08 11:37:49 +00:00
.catch((error) => {
console.error(error);
2021-04-10 13:34:55 +00:00
send(`${error}\nPlease use the following list: https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes`);
});
}
});