#api issue with translation
33 messages · Page 1 of 1 (latest)
the docs for @vitalets/google-translate-api say you need to destructure translate when importing it
It's not the default export for the package, just like how const Client = require('discord.js') would be different than const { Client } = require('discord.js')
I deleted that crap package
I'm using another rn
I'll post current issue
const prefix = '!';
client.on('messageCreate', async message => {
if (message.author.bot) return;
if (message.channel.type === ChannelType.DM) return;
if (message.content.startsWith(prefix + 't')) {
const args = message.content.slice(prefix.length + 2).split(' ');
const messageId = args[0];
const repliedTo = await message.channel.messages.fetch(messageId);
if (!repliedTo) {
return message.reply('Could not find the referenced message.');
}
const contentToTranslate = repliedTo.content;
translate(`${contentToTranslate}`, { to: 'en' })
.then(res => {
console.log(res);
message.reply(`Translation: ${res}`);
})
.catch(err => {
console.error(err);
});
}
});
```its saying translated: underined so its not getting the replied to message
its not getting the replied to message
await message.channel.messages.fetch(...)throws an error if Discord couldn't find the message, so at the very least,repliedTois either a Message instance andcontentToTranslateis a string, orrepliedTois a Collection of Message instances andcontentToTranslateisundefined
can you share which non-crap package you're using right now
I've gotten it to now register it's just saying the content is undefined when sending translation
Is undefined also logged in your terminal?
Yes
All I need for intents on this is the MessageContent right?
Well and GuildMessages
Guilds also wouldn't hurt
but the docs for your package say that res literally cannot return undefined
If you log contentToTranslate, is it what you're expecting it to be?
No
Undefined
It's not grabbing the replied to content
But I think I'm doing it right?
What does messageId log?
That might be an issue lol
i didnt see that you updated your code
Yeah I sent updated up above
yeah that would be it, but const repliedTo = await message.fetchReference() would also work
.
just know that your if (!repliedTo) statement will never be reached because promises throw errors if not found, instead of returning null or undefined
const repliedTo = await message.fetchReference()
Nothing inside for parameter?
Nope, you can check the docs