tmijs / tmi.js

💬 Javascript library for the Twitch Messaging Interface. (Twitch.tv)
https://tmijs.com
MIT License
1.55k stars 215 forks source link

Cannot send anonymous messages #350

Closed matcool closed 5 years ago

matcool commented 5 years ago

Actual behaviour: When trying to do client.say, i just get an error saying "Cannot send anonymous messages"

Expected behaviour: The message being sent

Code

require('dotenv').config()
const tmi = require('tmi.js')

const opts = {
    indentity: {
        username: process.env.BOT_USERNAME,
        password: process.env.OAUTH_TOKEN
    },
    channels: [process.env.CHANNEL_NAME]
}

const client = new tmi.client(opts);

client.on('message', (target, context, msg, self) => {
    if (msg.trim() === '!ping') {
        client.say(target, 'Pong!')
            .then(_ => console.log('message sent!'))
            .catch(msg => console.log(`New error! ${msg}`));
    }
});
client.on('connected', (addr, port) => {
    console.log(`Connected to ${addr}:${port}`);
});

client.connect();

Server configuration

AlcaDesign commented 5 years ago

Try logging the BOT_USERNAME and OAUTH_TOKEN to ensure they are being loaded by dotenv. (Or logging their type and length if you're squirmish about logging the raw values)

If that seems fine try enabling debug (new tmi.client({ options: { debug: true }, identity: { ... }, channels: [ ... ] }))

This could also be a temporary outage of some Twitch system or bad tokens. (Missing scope or expired token)