Search code examples
javascripttypescripttsc

TypeScript ':' expected


I'm having a problem with TypeScript compiler that expects a : in 17, 5 but I can't understand why and where to put it, my code:

import { Client , TextChannel } from "discord.js";

module.exports = {
    name: "ready",
    run: async(client: Client) => {
        client.user.setPresence({
            activities: [{
                name: "Aun en beta!"
            }],
            status: "idle"
        })

        let str = `-- censored --`
        let channel: TextChannel; 
        channel = client.channels.cache.get('-- censored --')?
        channel.send (str)
    }
}

Solution

  • the problem was with a ? as mentioned in the comment. also you forgot many semicolons in your code that I added.

    I edited your hole code and here it is:

    if you meant a null check by that ? then you had to place it somewhere else... see this below

    import { Client , TextChannel } from "discord.js";
    
    module.exports = {
        name: "ready",
        run: async (client: Client) => {
            client.user.setPresence({
                activities: [{
                    name: "Aun en beta!"
                }],
                status: "idle"
            });
    
            let str = `-- censored --`;
            let channel: TextChannel;
            channel = client.channels.cache?.get('-- censored --');
    //                                     ^^                     ^
            //                                            problem was here
            channel.send(str);
        }
    };