Discord.js - Im wondering how to un-server mute my bot when it gets server muted - discord.js

Sort of like how the Groovy bot automatically self-defans, im wondering how to do the same thing but opposite and for muting. Basically when the bot detects it has been server muted, it will automatically un-server mute. Thanks!

This might work:
client.on('voiceStateUpdate', (oldState, newState) => {
if(newState.id === client.user.id && newState.serverMute) newState.setMute(false); // unmute bot
});

Related

Discord: Reading messages from one channel in a (non-admin perm) server, and posting it to another (with admin perms)

I am new to Discord API framework.
ServerFROM is a public server that I was invited to (non-admin perms). Hence I cannot add bots there. But I can view the content in ChannelFROM (a text channel in ServerFROM)
I have my own ServerTO (in which I have admin perms and so can do anything). Inside of which, I have the target ChannelTO
I want to deploy a listener on ChannelFROM, such when there is a new message (announcement) in ChannelFROM, I want it to be read and reposted in ChannelTO.
Something similar to what is done in this Stackoverflow issue, except that I cannot have some script run locally 24x7 on my machine. Maybe use Github Actions or something similar?
How can I go about doing it? Any ideas are appreciated. Maybe some form of a server, or just a custom Discord bot
And thanks in advance.
you can use Custom bot for that. I dont know other way
here's how i do it
1st : We Get the ID of the Channel that you wanted to listen
2nd : We make a Output or where the bot copy the message from and send it
3rd : Bot required a permission to view the channel and send message
or in the nutshell ( sorry if im bad at explaining )
client.on("messageCreate", message => {
if(message.author.bot) return;
if(message.channel.id === ID_HERE) // ChannelFROM in ID_HERE
{
let MSG = message.content
let Author = message.member.displayName
let Avatar = message.author.displayAvatarURL({dynamic: true})
const Embed = new MessageEmbed()
.setAuthor(Author , Avatar )
.setDescription(MSG)
.setColor("RANDOM")
client.channels.cache.get(ID_HERE).send({ embeds: [Embed] }) // SendTo in ID_HERE
}
})
you can remove if(message.author.bot) return; if you want it also read other bot message on that specific channel

Im trying to do a reaction role bot on discord

client.on('messageReactionAdd', async (reaction, user) => {
if(reaction.message.id === "731619243249893417"){
const guildMember = reaction.message.guild.members.cache.get(user.id)
if(!guildMember.roles.cache.get("692177977705889845")){
guildMember.roles.add("692177977705889845");
Im using this code, but when i react to the message it
don't give me the role, im a starter needing help, thanks u all, and sorry for my english
Bots only listen for new messages. You have to tell them to listen for an old message explicitly to get a reaction from them. Try using this code. It fetches the message when a reaction is added to that message.

How to detect when a user joins a voice channel?

I am currently trying to make a bot for my server and one of the things I want to do is have it detect whenever a user joins any voice channel and simply make it send a message. I can't personally figure it out or find any answers on the internet as most of the time people are detecting it based on a command while I want it to be passive. I know that voiceStateUpdate has been changed and some things are different from how I've seen others use it in the past.
If anyone has any solutions please let me know, thanks.
client.on('voiceStateUpdate', (oldState, newState) => {
if (newState.channelID === null) console.log('user left channel', oldState.channelID);
else if (oldState.channelID === null) console.log('user joined channel', newState.channelID);
else console.log('user moved channels', oldState.channelID, newState.channelID);
});
In discord.js v.12 the listener you need to use is indeed voiceStateUpdate. It has the parameters oldState and newState. With those you can detect a number of things including the member object.
Using that you might use something like this to detect if a user or bot is connecting or disconnecting a voice channel.
client.on('voiceStateUpdate', (oldState, newState) => {
// check for bot
if (oldState.member.user.bot) return;
// the rest of your code
})

How to make my discord bot only work in a chat?

I am using discord.js to implement a bot in the discord. When I use a command in any channel in my server, my bot responds to it, but I would like that my bot only worked if someone was sending the commands inside a private chat with the bot, how do I do that?
If you only want it to work between DMs, do
if (!message.channel.type == `dm`) return;
//other commands
You can check if the message was sent in a certain channel by checking the Message.channel.id property.
client.on("message", message => {
if (message.channel.id !== "ChannelID") return false;
// Execute your commands here
});

Creating a Discord bot to notify people when to certain text on a website has changed

const Discord = require('discord.js');
const bot = new Discord.Client();
const token = '';
bot.on('ready', () =>{
console.log('This bot is online');
})
bot.on('message', msg=>{
if(msg.content === "?rates"){
msg.reply('.')
}
})
bot.login(token);
This is what I have so far it is very basic, I understand, I'm just trying to get some sort of idea how to process. What I want is as soon as a website gets updated or changed. I would like it to tag everyone and in a certain channel and specifies what has changed. I know this will be a long process but I'm in for the ride :) would appreciate any help.
You need a webhook on the website and listen to it with your bot, if you have control over the site, this may help you, otherwise you could look if the site has one or perhaps ask an owner.
A probably working but not very nice (and not very clean) solution would be to save the text of the website every 5 seconds or so and compare it to the previous save. If it changed, you notify the members through sending a message.

Resources