Approval/Denial System using Discord.js - discord.js

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

Related

Discord Autocode reaction reply bot (not reaction role bot)

I have been using autocode.com to create some Discord bots. I have very little programming experience and found autocode to be quite easy. However, I've tried asking a question on autocode's discord that no one seems to understand or is asking.
I am trying to create a bot that replies to reactions--but does not assign roles, but instead, provides a reply--either in thread or a DM to that user who uses that specific emoji reaction.
For example, this is what I am looking to do: if there is a bot message in #channelx, userX will react to that message with a pepperoni emoji and then a pizza bot will reply back with a message either in thread or DM such as, "Hi #userx, your pizza topping has been recorded and will be ready for pickup in 15 minutes, please visit this link.com to track your order".
Autocode has a bot that can react to reactions and assign roles but I can't seem to reverse engineer it give a reply, rather than assign roles.
I appreciate any assistance. Thanks!
What does autocode use? Python or node.js? If python, you can do something like this:
#client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('message'):
await message.channel.send('hi')
If node.js, you can do something like this:
client.on('messageCreate', msg => {
if (msg.content === 'specific message') {
msg.reply(`response text`);
}
});
I was previously a Community Hero at the Autocode Discord server. Try finding another app through this, and if none are available, the thing to do would be looking through the API's. Here's one for messaging in general, here's one for responding, and here's one for dm-ing.
Let's say, for example, I'd be making it reply to a reaction through DM:
The first thing you do is make sure the event trigger is set to message.reaction.add. This is so that the code you will write is triggered whenever a reaction is added.
Make either a switch or if statement to change what happens depending on what reaction triggers the code. In this example, I'll just use an if statement for easy explanation.
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
if (context.params.event.emoji.id == '1234567890') {
await lib.discord.users['#0.2.1'].dms.create({
recipient_id: `${context.params.event.member.user.id}`,
content: `Hi <#${context.params.event.member.user.id}>, your pizza topping has been recorded and will be ready for pickup in 15 minutes, please visit this link.com to track your order`
});
}
What this does is check if the thing that triggered this event has the emoji id equaling '1234567890': If it does, then it follows into that if statement, and if it does not, it skips over it.
In the future, please stay patient in the Autocode Discord server; The ones who are helping are also community members, similar to here. You may always ask the same question every now and then.

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

Discord.js - Check if user is muted / mute change

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

Obtain User ID from a DM message Sent To Bot

I want to find the user id of the person who DMs the bot. Is there any way to do it? I am using Discord.js
I tried by storing member author and member Id but it didn't work. But when I store channel, it store it as authors tag. But the id for that channel does not matches with the id of the user who DM the bot. I am trying to make support mail bot. But it requires the user id so that I can continue the thread by DMing the user. But it's not possible until I get the user id or server member object. And I can't store that DMchannel in my database because i use json for storing datas.
Due to my low reputation, I can't comment, sorry if this does not answer your question.
You can get the ID of the person who DM'd your bot by message.author.id (keep in mind, message will need to change to whatever variable your message is stored in).
You can also get the channel ID with message.channel.id.
The channel ID is not the same as the user's ID (they are two different things), which I assumed you misunderstood from id for that channel does not matchs with the id of the user who DM the bot.
Try this:
const client = new discord.Client();
client.login('token here');
/* On message event since you want to
* recieve DM and get ID from user who sent DM to your bot.
*/
client.on("message", (msg) => {
// checks if the message's channel type is 'DM'.
if(msg.channel.type === "dm") {
// you can do anything you want here. In my case I put console.log() function.
// since you wanted user ID, you can use msg.author.id property here.
console.log(`Recieved DM from ${msg.author.tag}, DM content is`, msg.content);
}
});
Please remember, author/member ID and dm message channel ID is completely separate thing.
Also storing member related data in JSON or an SQL is not a really good idea here. I suggest you only doing that for custom data you've generated, or that would be wasting a lot of memory.

Using guilds and channels without needing to read a message

I'm hosting my bot on glitch.com, but it restarts every night.
When my bot gets started, it reads a message from a specific channel and then writes in the others. The problem with this is that I can't use any guild or channel until the bot receives a message.
How can I avoid doing this?
You can use guild and channel IDs. Every element in Discord has a unique ID (called Snowflake) that identifies it.
If you want to get a specific guild or channel, you can save its ID and use it in the code. IDs are public, so there's no risk using them (they're not like passwords or tokens).
Guilds and channels are stored in Collections and mapped by their IDs, so you can use them like this:
let guild = client.guilds.get('guild id as a string');
let channel = guild.channels.get('channel id as a string');
To get your guild's ID (or the ID of pretty much any element in Discord) you can enable the Developer mode in the settings, then right-click on the guild and select "Copy ID".

Resources