How do I translate something in real time with "@iamtraction/google-Translate"?

Asked

Viewed 28 times

-1

const discord = require("discord.js");
const imdb = require("imdb-api");

module.exports = {
name: "imdb",
  description: "Obtenha informações sobre séries e filmes",
  category: "utilidade",
  usage: "imdb <name>",
  run: async (client, message, args, color) => {
    
    if(!args.length) {
      return message.channel.send("Por favor, dê o nome do filme ou série")
    }
    
    const imob = new imdb.Client({apiKey: "5e36f0db"}) //Você precisa colar sua imdb api
    
    let movie = await imob.get({'name': args.join(" ")})
    
    let embed = new discord.MessageEmbed()
    .setTitle(movie.title)
    .setColor("#ff2050")
    .setThumbnail(movie.poster)
    .setDescription(movie.plot)
    .setFooter(`Avaliações: ${movie.rating}`)
    .addField("País:", movie.country, true)
    .addField("Idiomas:", movie.languages, true)
    .addField("Tipo:", movie.type, true);
    
    
    message.channel.send(embed)
    
    
    
  }

}

This is a command of a bot where the user puts for example: k! imdb How i met your Mother and the bot returns the series information obtained by the api of IMDB, only that the information is in English and I would like to know how I translate this to Portuguese in real time with the @iamtraction/google-Translate

comando em execução

1 answer

0


Just install this module that you quoted, importing it into your code using the require and call it within its function, for example:

const discord = require("discord.js");
const imdb = require("imdb-api");
const googleTranslate = require("@iamtraction/google-translate");

module.exports = {
name: "imdb",
  description: "Obtenha informações sobre séries e filmes",
  category: "utilidade",
  usage: "imdb <name>",
  run: async (client, message, args, color) => {
    
    if(!args.length) {
      return message.channel.send("Por favor, dê o nome do filme ou série")
    }
    
    const imob = new imdb.Client({apiKey: "5e36f0db"}) //Você precisa colar sua imdb api
    
    let movie = await imob.get({'name': args.join(" ")})

    const plot = await googleTranslate(movie.plot, { from: 'en', to: 'pt' })
    
    let embed = new discord.MessageEmbed()
    .setTitle(movie.title)
    .setColor("#ff2050")
    .setThumbnail(movie.poster)
    .setDescription(plot.text)
    .setFooter(`Avaliações: ${movie.rating}`)
    .addField("País:", movie.country, true)
    .addField("Idiomas:", movie.languages, true)
    .addField("Tipo:", movie.type, true);
    
    
    message.channel.send(embed)
    
    
    
  }

}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.