Hello there, I have a simple bot created with node.js and tmi.js library.
So far I managed to connect the bot to my channel and listen for messages but problem comes when I want to delete a message.
According tmi.js documentation, in order to use the method to delete a certain message you need 2 arguments: channel and message ID.
At this point, I found that there is already a question in this link, basically I am having the same problem but with a specific error message: You don’t have permission to perform that action.
Here below a code sample to replicate my error
const tmi = require('tmi.js');
const opts = {
identity: {
username: '<BOT_USERNAME>',
password: '<OAUTH_TOKEN>'
},
channels: [
'<CHANNEL_NAME>'
]
};
const client = new tmi.client(opts);
client.on('message', onMessageHandler);
client.on('connected', onConnectedHandler);
client.connect();
function onMessageHandler (target, context, msg, self) {
if (self) { return; }
if (msg === 'ciao') {
client.deletemessage(channel, context.id);
}
function onConnectedHandler (addr, port) {
console.log(`* Connected to ${addr}:${port}`);
}
Below my context object
context {
'badge-info': null,
badges: { broadcaster: '1' },
'client-nonce': 'xxxxxxxxxxxx',
color: null,
'display-name': 'a_name',
emotes: null,
'first-msg': false,
flags: null,
id: 'xxxxxxxxxxxxxxx',
mod: false,
'returning-chatter': false,
'room-id': xxxxxxxxx
subscriber: false,
'tmi-sent-ts': 'xxxxxx',
turbo: false,
'user-id': 'xxxxxxxxxx',
'user-type': null,
'emotes-raw': null,
'badge-info-raw': null,
'badges-raw': 'broadcaster/1',
username: 'a_name',
'message-type': 'chat'
}
Am I missing something in the setup of my app? I do realize that this may come from user role (which in my case is set to “broadcaster”) but after many hours I could not find a proper thread or solution to this.
Edit: worth to mention, there is an explanation on this page about /delete command:
A bot may not delete the broadcaster’s messages.
I tried to delete a msg from a separate account not connected to the bot in the target channel, but I still got the same error mentioned in the title.