#api issue with translation

33 messages · Page 1 of 1 (latest)

jaunty sphinxBOT
#
  • Consider reading #how-to-get-help to improve your question!
  • Explain what exactly your issue is.
  • Post the full error stack trace, not just the top part!
  • Show your code!
  • Issue solved? Press the button!
proud island
#

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')

winged ether
#

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
proud island
#

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, repliedTo is either a Message instance and contentToTranslate is a string, or repliedTo is a Collection of Message instances and contentToTranslate is undefined

#

can you share which non-crap package you're using right now

winged ether
#

I've gotten it to now register it's just saying the content is undefined when sending translation

proud island
#

Is undefined also logged in your terminal?

winged ether
#

Yes

#

All I need for intents on this is the MessageContent right?

#

Well and GuildMessages

proud island
#

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?

winged ether
#

No

#

Undefined

#

It's not grabbing the replied to content

#

But I think I'm doing it right?

proud island
#

What does messageId log?

winged ether
#

That might be an issue lol

proud island
#

i didnt see that you updated your code

winged ether
#

Yeah I sent updated up above

proud island
#

yeah that would be it, but const repliedTo = await message.fetchReference() would also work

winged ether
proud island
#

just know that your if (!repliedTo) statement will never be reached because promises throw errors if not found, instead of returning null or undefined

winged ether
#

const repliedTo = await message.fetchReference()
Nothing inside for parameter?

proud island
#

Nope, you can check the docs

winged ether