This is an AI-powered Discord bot that automatically translates non-English messages to English in real-time. With seamless integration and lightning-fast translation, TranslateBot helps to bridge language barriers and bring people together in global communities
// authenticates you with the API standard library
// type `await lib.` to display API autocomplete
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
// first make a call to open ai
try {
let message = await lib.openai.playground['@0.0.4'].completions.create({
model: `text-davinci-003`,
prompt: [`Translate this to English :${context.params.event.content}. `],
max_tokens: 64,
temperature: 0.4,
top_p: 1,
n: 1,
echo: false,
presence_penalty: 0,
frequency_penalty: 0,
best_of: 1,
});
await lib.discord.channels['@0.3.4'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: `${message.choices[0].text}`, // the response is an array. So we send only the first one from it.
});
} catch (e) {
await lib.discord.channels['@0.3.4'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: `${e}`,
});
}