How to make bot change channel permissions? - discord

So, the Discord bot that I'm making is sort of a server manager kind of thing and I'm making a channel lock command which basically makes it so people can't send messages in the channel.
How would I make it so that when someone types the command it turns the 'Send Messages' permission FALSE?
Any help is appreciated! Thanks.

const Channel = client.channels.cache.get("ChannelID");
if (!Channel) return console.log("Invalid channel ID.");
Channel.updateOverwrite(message.guild.roles.everyone, {SEND_MESSAGES: false});

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

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
});

Discord bot that sends an message to a channel whenever a message is deleted. Discord.js

I’m trying to make my bot send a message to a channel whenever a user deletes his/her message, sorta like the bot Dyno, but I do not know how to do this. I think the method is .deleted() but I can’t seem to make it work. Can anyone tell me how? Sorry for lack of detail, there’s nothing else to add. Thank you in advance.
The Client (or Bot) has an event called messageDelete which is fired everytime a message is deleted. The given parameter with this event is the message that has been deleted. Take a look at the sample code below for an example.
// Create an event listener for deleted messages
client.on('messageDelete', message => {
// Fetch the designated channel on a server
const channel = message.guild.channels.cache.find(ch => ch.name === 'deleted-messages-log');
// Do nothing if the channel wasn't found on this server
if (!channel) return;
// Send a message in the log channel
channel.send(`A message has been deleted. The message was: ${message.content}`);
});

I'm making a discord bot and want it to DM a user

So I'm making a kick command for my discord bot and I want the bot to DM the user telling them they have been kicked. So far I have got:
case 'kick':
const Embed = new
Discord.MessageEmbed()
.setTitle('Success!')
.setColor(0x00FF00)
.setDescription(`Successfully kicked **${args[2]}** \n \n**Message:** \n"${args.join(' ')}"`)
if(!message.member.hasPermission(['KICK_MEMBERS'])) return message.channel.send('*Error: You do not have permission to use* **kick**.');
if(!args[1]) return message.channel.send('*Error: Please specify a user to kick!*');
let member = message.mentions.members.first();
member.kick().then((member) => {
message.channel.send(Embed);
})
break;
So far, the user is successfully kicked so all this works.
All I need to know is how to make the bot DM the mentioned user to tell them they have been kicked. Any help is appreciated!
You are probably looking for this method: GuildMember#send()
member.send("Your DM Here");
Note that if the only reason your bot could send a member DMs was because of a mutual server in which the user had DMs from server members enabled (user disabled other types of stranger DMs), then your bot would not be able to send the DM. It would probably be a good idea to send them the DM and wait for the method's returned promise to resolve before kicking them, for a higher chance that the DM actually reaches them.

Reply to anyone who sent a DM

EDIT: Another question with better answers: How to reply to any DMs sent to the bot?
Is it possible to reply to someone who sent a message to my Discord.js bot?
For example, when someone sends hi to my bot's DMs, the bot should reply Please use !help for the commands' list.
I've tried a lot of attempts to use the MessageCollector but I failed doing it.
Any help would be appreciated.
Thanks!
You can just tell the bot to do that with client.on('message').
Try this:
client.on('msg', () => {
if (msg.channel.type == 'dm' && msg.content.toLowerCase() == 'hi')
msg.channel.send('Please use !help for the commands' list.')
})
This is just a quick example, but you can also add checking for commands and all the other stuff that you do on normal guild channels. To check if the message comes from a DMChannel is to check Channel.type

Resources