When I try running my WhatsApp Bots using whatsapp-web.js module and making if Admins using a .setSMAO (Send Messages Admin Only) true, it will automatically set the Group Settings Send Messages to Admin Only
I search the methods on https://docs.wwebjs.dev/GroupChat.html and found GroupChat.setMessagesAdminsOnly();
I tried adding it and then test it but instead of working, I just met this error
GroupChat.setMessagesAdminsOnly();
^
TypeError: GroupChat.setMessagesAdminsOnly is not a function
at Client.<anonymous> (D:\WhatsApp Bots keenan\bot.js:240:14)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
The code:
client.on('message', async msg => {
const chat = await msg.getChat();
const contact = await msg.getContact();
if (msg.body == '.setSMAO true') {
if (chat.isGroup) {
let chat = await msg.getChat();
GroupChat.setMessagesAdminsOnly();
msg.reply('Successfully changed the Group Settings.');
console.log('[CHANGED_SEND_MESSAGE_TO_ADMIN_ONLY] There was an Admin that changed the Group Settings Send Message to Admin Only');
} else {
msg.reply('This command only works on Group or the Bot didn't have an Admin Permissions!');
}
}
});
What did I do? Did I just typing it wrong?
GroupChat is an class/constructor for chats where Messages can appear, similar to Chat. And instances of them will be returned on a message with message.getChat().
You already did the right part with the check for chat.isGroup, so all you have to do afterwards is calling groupChatInstance.setMessagesAdminsOnly() which is possible on the same referrence by replacing GroupChat.setMessagesAdminsOnly() with chat.setMessagesAdminsOnly().