I am trying to create a bot that server-mutes everyone if a specific person mutes themself.
I can get the user ID or other details via message.member.
Is there any way to find out if that user is muted or even if the person is in a voice channel?
This is what I found so far:
client.on('voiceStateUpdate', (oldmember, newmember) => {
let oldvoice = oldmember.voiceChannel;
let newvoice = newmember.voiceChannel;
if (oldvoice && newvoice && oldvoice.id != newvoice.id)
var channelStatus = 'Moved'
console.log(oldvoice)
})
But I don't understand it and it just returns undefined.
Edit: Found a way easier solution:
msg.member.voice.selfMute
Old one:
client.channels.cache.get(msg.member.voice.channel.id).guild.voiceStates.cache.get(msg.author.id).selfMute
let's break it down:
client.channels.cache gives you of all text and voice channels in your discord server
get(msg.member.voice.channel.id) gives you the id of the voice channel, the user that wrote the bot command (considering, you have stored the message in a variable e.g.: msg)
.guild.voiceStates.cache gives you a list of everyone in the channel
.get(msg.author.id) takes the user that wrote the last message
.selfMute returns the mute state
btw there are other pretty useful things too like selfDeafen, streaming and more
Related
DISCORD.JS
Hey! So, recently, I was on a server that contained an amazing bot. That was an approval or denial system. So, what would happen for example, somebody would sign a google form and the google script will send the response via a webhook (I already know that code) in an embed to a private channel named "awaiting-result", now, the bot will automatically add reactions to the message, for example, ✅ and ❌. Then, a staff member will react with either one of those emojis and it will send to two different channels. If the reaction was a ✅, then the bot will remove all reactions from the original message, copy the exact embed from the google form response, and send it to a channel named "accepted-logs" with a message above it "Your log has been accepted by ${person}". If it was an ❌, it will do the exact same thing as the approved one. I have been trying hard, but cant find it. All I ready need is the bot code, not the form script. So basically, you react, copy the exact embed, send to another channel. Itll be very helpful, thanks!
List of useful links:
https://discordjs.guide/popular-topics/reactions.html#unicode-emojis
https://discordjs.guide/popular-topics/collectors.html#reaction-collectors
https://discordjs.guide/popular-topics/embeds.html#using-the-embed-constructor
I'm pretty sure you could just store the embed contents in an Object, then you can wait for the collector to collect a ✅ or ❌, check if the user has admin role (e.t.c), and then find the channel the embed needs to be sent too
let channel = client.channels.cache.find(channel => channel.name === "name");
and then you can send the embed to the channel via
channel.send(embed);
In order to make an embed, you just do:
let embed = new Discord.MessageEmbed();
And then you can add fields to it (see link #3). Then you can simply just do
let approvalChannel = client.channels.cache.find(channel => channel.name = "admin-approval");
approvalChannel.send(embed);
// Code for reaction collector
This is my code and It seems the random user selection is broken although it works completely fine in another command I have that pings a random user
client.on('message', message => {
if (message.content.toLowerCase() === `${prefix}command`) {
const userList = message.guild.members.cache.array();
var randomNumber = Math.floor(Math.random() * userList.length)
var dm = userList[randomNumber]
console.log(dm.user.id)
dm.send("123");
}
ok, so the code you have written works just fine. The problem is that your bot cannot send a message to its self. There is a very easy solution to this. Just check if the selected member is a bot and return if that's the case. Note: I put your random number inside the array field of the userList.
const userList = message.guild.members.cache.array();
var dm = userList[Math.floor(Math.random() * userList.length)];
if (dm.user.bot) return;
console.log(dm.user.username);
dm.send("123");
Note: If you only have yourself and the bot on your test server then this will only ever send a DM to you. In that case I would recommend getting a secondary account and inviting some friends to the test server.
Have you enabled the members intent? The members list only shows you and the bot if you don't have that intent enabled. Read the docs for intents for more information.
I'm making a discord bot that will has a feature to move user's to a random voice channel if they want. I searched the internet 3 hours straight and checked the whole documentation. But still can't find anything.
note : I know this bot idea looks useless. But that's what I need.
code :
let voiceChannels = message.guild.filter(g => **idk how to check if it's vc** );
that's what I just found in 3 hours.
You'd need to access the guild's channels and then choose a random channel of type voice.
So in your case, it'd be:
let voiceChannel = message.guild.channels.cache.filter((channel) => channel.type === "voice").random();
if (!message.member.voice.channel) return message.reply("User is not in a voice channel");
await message.member.voice.setChannel(voiceChannel);
I'm trying to basically do what the title says.
I've tried
let channel = message.channel.get(68352726916713XXXX)
message.channel.send(channel.topic)
and stuff like that, But nothing works.
Any suggestions or answers?
If you are trying to get a channel in the same guild as the message was sent in, use message.guild.channels.get. Otherwise, use client.channels.get.
let channel = message.guild.channels.get("68352726916713XXXX");
message.channel.send(channel.topic);
I promise, I've tried everything. I think I have the actually command down, but I can't figure out how to implement the name of the voice channel. Here's my code:
if (!message.mentions.users.first()) {
message.channel.send("You have to tag someone my dude.")
break;
}
var member = (message.mentions.users.first())
guild.member(member).setVoiceChannel(Rats)
message.channel.send(":right_facing_fist: " + member)
break;
It runs through just fine, but "Rats" (the voice channel) is undefined. Do I need a variable that has the voice channel name? Is there something else I'm doing wrong?
Thanks in advance :)
Seems like your code is fine to me, but the Assignment of Rats is wrong.
setVoiceChannel() method takes in an argument which is a channel with type voice. So all you have to do is just directly assign the voiceChannel object to Rats and it would work.
You can get the list of channels in a guild by message.guild.channels, which returns a Collection<Snowflake,Guildchannel>. From there, you can filter out all the non-VCs using filter . You can do channel.type === "voice" to check if a channel is a voice channel or not.