Ask coding questions

← Back to all posts
error
h
danbaker1986

/home/runner/StreamersDen/index.js:9
return;
^^^^^^

SyntaxError: Illegal return statement

whats this mean?

Voters
danbaker1986
Comments
hotnewtop
danbaker1986

whats that mean?

danbaker1986

/home/runner/StreamersDen/index.js:70
const tmi = require("tmi.js");
^

SyntaxError: Identifier 'tmi' has already been declared

danbaker1986

It doesnt like this code here. So odd

danbaker1986

Which is odd as this scriot works fine on my digital ocean account. But here is much easier so wanted to move it over

danbaker1986

This is the code

danbaker1986

const tmi = require("tmi.js");
const dateFormat = require("dateformat");
const config = require("./config");

const {username, token, channels} = config

if (!username) {
console.error("[ERROR] You need to provide a username!");
return;
}

if (!token) {
console.error("[ERROR] You need to provide a client token!");
return;
}

if (!channels || channels.length < 1) {
console.error("[ERROR] You need to provide at least one channel!");
return;
}

const user = username.toLowerCase();

const tmiOptions = {
connection: {
reconnect: true,
secure: true
},
identity: {
username: user,
password: token
},
channels: channels
}

const getCurrentTime = () => {
const d = new Date();
return [${dateFormat(d, "yyyy-mm-dd HH:MM:ss")}];
}

const client = new tmi.client(tmiOptions);
client.connect();

client.on("logon", () => {
console.log(${getCurrentTime()} Connecting to the Twitch server as user "${user}"...);
});

client.on("join", (channel, username) => {
if (username == user) {
console.log(${getCurrentTime()} Joined channel "${channel.substring(1)}".);
}
});

client.on("subgift", (channel, username, _, recipient) => {
if (recipient.toLowerCase() == user) {
console.log(${getCurrentTime()} Received a subscription gift from user "${username}" in channel "${channel.substring(1)}"!);
}
});

client.on("reconnect", () => {
console.log(${getCurrentTime()} Trying to reconnect to the Twitch server...);
});

client.on("part", (channel, username) => {
if (username == user) {
console.log(${getCurrentTime()} Disconnected from channel "${channel.substring(1)}".);
}
});
const tmi = require("tmi.js");
const dateFormat = require("dateformat");
const config = require("./config");

const {username, token, channels} = config

if (!username) {
console.error("[ERROR] You need to provide a username!");
return;
}

if (!token) {
console.error("[ERROR] You need to provide a client token!");
return;
}

if (!channels || channels.length < 1) {
console.error("[ERROR] You need to provide at least one channel!");
return;
}

const user = username.toLowerCase();

const tmiOptions = {
connection: {
reconnect: true,
secure: true
},
identity: {
username: user,
password: token
},
channels: channels
}

const getCurrentTime = () => {
const d = new Date();
return [${dateFormat(d, "yyyy-mm-dd HH:MM:ss")}];
}

const client = new tmi.client(tmiOptions);
client.connect();

client.on("logon", () => {
console.log(${getCurrentTime()} Connecting to the Twitch server as user "${user}"...);
});

client.on("join", (channel, username) => {
if (username == user) {
console.log(${getCurrentTime()} Joined channel "${channel.substring(1)}".);
}
});

client.on("subgift", (channel, username, _, recipient) => {
if (recipient.toLowerCase() == user) {
console.log(${getCurrentTime()} Received a subscription gift from user "${username}" in channel "${channel.substring(1)}"!);
}
});

client.on("reconnect", () => {
console.log(${getCurrentTime()} Trying to reconnect to the Twitch server...);
});

client.on("part", (channel, username) => {
if (username == user) {
console.log(${getCurrentTime()} Disconnected from channel "${channel.substring(1)}".);
}
});

client.on("disconnected", (reason) => {
console.log(${getCurrentTime()} Disconnected from the Twitch server. Reason: "${reason}".);
});

client.on("disconnected", (reason) => {
console.log(${getCurrentTime()} Disconnected from the Twitch server. Reason: "${reason}".);
});

SixBeeps

@danbaker1986 Oh, you can't use return unless it's in a function. I think you're looking for process.exit(1) instead.

NFadhlurrahman

@danbaker1986

You cannot use return outside a function.

SixBeeps

We can't see your code, but a "syntax error" means you typed something in wrong. The line you gave seems to be fine, so the problem is likely with the line before where the error is. Double-check that you haven't missed a ) or a } somewhere.