Skip to content

Instantly share code, notes, and snippets.

@tika
Created October 24, 2019 19:38
Show Gist options
  • Save tika/0a110ff08668564fe251d40831789968 to your computer and use it in GitHub Desktop.
Save tika/0a110ff08668564fe251d40831789968 to your computer and use it in GitHub Desktop.
const Discord = require('discord.js');
const fs = require('fs');
const translate = require('@vitalets/google-translate-api');
const config = require('../config.json');
exports.run = (client, message, args) => {
// !translate spanish hello my name is jeff
//
let raw = args.slice(1).join(" ");
if(!args[0] || !raw) return message.channel.send(`Invalid syntax, proper syntax: ${config.prefix}translate <language> <text>`)
translate(raw, {to: translate.languages.getCode(args[0])}).then(res => {
let embed = new Discord.RichEmbed()
.setColor('#fcb103')
.setTitle("**Translate**")
.addField(`From **${res.from.language.iso}**`, raw)
.addField(`To **${translate.languages.getCode(args[0])}**`, res.text)
.setFooter(`Services provided by Google Translate`, 'https://cdn.discordapp.com/attachments/633079489219395594/637008814847033364/google-translate_logo.png');
message.channel.send(embed);
}).catch(err => {
console.log(err);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment