I'm having a problem with TypeScript piler 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)
}
}
I'm having a problem with TypeScript piler 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)
}
}
Share
Improve this question
asked May 17, 2021 at 4:38
akkoboiakkoboi
391 gold badge1 silver badge6 bronze badges
1
-
3
channel = client.channels.cache.get('-- censored --')?
why is there a?
at the end? Did you want;
insteand? – Hao Wu Commented May 17, 2021 at 4:44
2 Answers
Reset to default 2the problem was with a ?
as mentioned in the ment.
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);
}
};
At the end of line channel = client.channels.cache.get('-- censored --')?
due to ?
piler expect that it as a conditional (ternary) operator (condition ? exprIfTrue : exprIfFalse
) so throw ':' expected
error.
May be it's a typo and should be like channel = client.channels.cache.get('-- censored --');
Or it should be like channel = client.channels.cache?.get('-- censored --');
.