Help

hey, just need help with something. When I invoke the command, it reacts on the embed. (I forgot the code to do that feature lol)
38 Replies
informed
informedOP2y ago
my verision is this.
Lioness100
Lioness1002y ago
Please elaborate on what "it reacts on the embed" means
informed
informedOP2y ago
As soon as I invoke the command, it shows this, then i want the bot to react on the invoked embed.
Lioness100
Lioness1002y ago
Oh
informed
informedOP2y ago
Example:
informed
informedOP2y ago
Lioness100
Lioness1002y ago
discord.js Guide
Imagine a guide... that explores the many possibilities for your discord.js bot.
Lioness100
Lioness1002y ago
basically, where you write, message.channel.send(...), change that to const sentMessage = await message.channel.send(...) (make sure the function is async). Then, on the next line, you can use await sentMessage.react(...) (using the guide page to see what you pass to that function)
Lioness100
Lioness1002y ago
discord.js Guide
Imagine a guide... that explores the many possibilities for your discord.js bot.
informed
informedOP2y ago
This is my updated one.
Ben
Ben2y ago
Your reacting to whatever message the message variable represents, not the one sent on line 97. Store the response from 97 in a new variable or const and react to that like Lioness recommended
Lioness100
Lioness1002y ago
Also it would be helpful if you could send your code in text instead of screenshotting it
informed
informedOP2y ago
okay 1 sec
if(message.content === prefix + "activitycheck") {
channel1 = message.guild.channels.cache.find(r => r.name === "activity_checks")
if (channel1) {
if (!message.member.roles.cache.some(role => role.name === 'Management')) return message.author.send("
if(message.content === prefix + "activitycheck") {
channel1 = message.guild.channels.cache.find(r => r.name === "activity_checks")
if (channel1) {
if (!message.member.roles.cache.some(role => role.name === 'Management')) return message.author.send("
You Do Not Have The Correct Permissions To Run This Command
"), message.react("❌")
let embed = new EmbedBuilder()
.setColor(0x0099FF)
.setTitle("**Activity Check**")
.setDescription("> **Please React Below Proving That You Are Active (:below:)**")
.setThumbnail("https://media.discordapp.net/attachments/1038860507467227176/1047544499812974612/standard.gif?width=205&height=205")
.setTimestamp()
.setFooter({ text: `Invoked By ${message.author.username} • ${message.guild.name}`});
(async() => {
let m = await channel1.send("@everyone")
await m.delete();
})();

await channel1.send({embeds: [embed]})
await message.react("✅")
await message.delete()
}
}
"), message.react("❌")
let embed = new EmbedBuilder()
.setColor(0x0099FF)
.setTitle("**Activity Check**")
.setDescription("> **Please React Below Proving That You Are Active (:below:)**")
.setThumbnail("https://media.discordapp.net/attachments/1038860507467227176/1047544499812974612/standard.gif?width=205&height=205")
.setTimestamp()
.setFooter({ text: `Invoked By ${message.author.username} • ${message.guild.name}`});
(async() => {
let m = await channel1.send("@everyone")
await m.delete();
})();

await channel1.send({embeds: [embed]})
await message.react("✅")
await message.delete()
}
}
So what would I do exactly?
Ben
Ben2y ago
You do what is described here
Lioness100
Lioness1002y ago
Change
await channel1.send({embeds: [embed]})
await message.react("✅")
await channel1.send({embeds: [embed]})
await message.react("✅")
To
const sentMessage = await channel1.send({embeds: [embed]})
await sentMessage.react("✅")
const sentMessage = await channel1.send({embeds: [embed]})
await sentMessage.react("✅")
I'd also recommend learning some more js basics
Spinel
Spinel2y ago
Before you make a Discord Bot, you should have a good understanding of JavaScript. This means you should have a basic understanding of the following topics: - Read and understand docs - Debug code - Syntax - NodeJS module system If you aren't sure that your understanding of JavaScript is truly good enough to make a bot, you should really try to continue learning first. Here are good resources to learn both Javascript and NodeJS: Codecademy: https://www.codecademy.com/learn/javascript Udemy: https://www.udemy.com/javascript-essentials/ Eloquent JavaScript, free book: http://eloquentjavascript.net/ You-Dont-Know-JS: https://github.com/getify/You-Dont-Know-JS JavaScript Garden: https://bonsaiden.github.io/JavaScript-Garden/ JavaScript reference/docs: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference Nodeschool: https://nodeschool.io/ Pluralsight: https://www.codeschool.com/courses/real-time-web-with-node-js Before you ask a question, you should ask these yourself: 1) Is this question related to JavaScript, or the library I am using? - If it is the library you are using, go to the proper server. You would get better answers there. 2) Have I tried to google and / or check StackOverflow? - Double check that you can't find anywhere that can lead you to a solution online. 3) Have I tried to look on MDN or the library documentation? - You should always check documentations to make sure you aren't missing how any details. 4) Does my question make enough sense so that people can understand it, and do they understand what I am trying to accomplish? - If no, revise your question. Give as much detail as possible. Include any error or code output that can help us help you. 5) Am I aware of what I am doing, and not just mindlessly copy and pasting? - If you are just copy and pasting code from a guide, you are not going to be able to solve anything. Make sure you understand the code you are writing.
informed
informedOP2y ago
Okay. Thank you so much!!
Alexandre
Alexandre2y ago
You can also use "Then" and "Catch". "Then" so you don't have to pause the code to wait for the message to be sent and for the reaction to be use only if it's good. "Catch" to be sure that the asynchronous function (detached from the process) will not make an error that could crash your bot. When you use await in the main process the bot is in pause. In thread and process, all error not catch will be display and the program will close
Lioness100
Lioness1002y ago
That's not true
Alexandre
Alexandre2y ago
Explain
Lioness100
Lioness1002y ago
await only blocks the scope it's called in and everything after it (in that block) Since there's nothing else in the function, the await isn't blocking anything Synchronous functions are what block the main thread That's the whole point of async
Alexandre
Alexandre2y ago
That's what I said
Lioness100
Lioness1002y ago
No, you said it blocks the main thread Those are very different haha
Lioness100
Lioness1002y ago
Lioness100
Lioness1002y ago
I think you just mixed the terms up, because synchronous methods are what block the main thread For example, all of the fs sync methods However, fs/promises methods do not
Alexandre
Alexandre2y ago
Okkk, the first call come from an async? But you are right
Lioness100
Lioness1002y ago
?
Alexandre
Alexandre2y ago
If you make an async call from the top, or the call come from an async event emitter (I think that it could be the same) and everything is await, the bot will be in pause If you use discordjs you always have this issues If you use sapphire I think that it have things to break that
Lioness100
Lioness1002y ago
Again, I'm pretty sure that's not true Could you send a short code example so I can visualize what you're saying?
Alexandre
Alexandre2y ago
I will try Maybe you're right
Lioness100
Lioness1002y ago
From the top (global scope), then I agree, but not from an async event emitter
Alexandre
Alexandre2y ago
If you are right, I don't know why my bot was in pause when I was using command 😅
Lioness100
Lioness1002y ago
Mostly because I don't think async event emitter exists KEKW you mean a client.on function that passes an async callback?
Alexandre
Alexandre2y ago
Yes
Lioness100
Lioness1002y ago
👍
Alexandre
Alexandre2y ago
Global scope I'm also sure
Lioness100
Lioness1002y ago
But also, if you didn't want to block the top scope with an async function, just put it at the bottom of the entry file And if you can't, because something else depends on it being done, then it blocked the top scope for a reason haha
Alexandre
Alexandre2y ago
@Lioness100 you are right sorry my test was
const EventEmitter = require("events");
const emitter = new EventEmitter();

let amount = 0;

emitter.on(
"test",
() =>
new Promise((resolve, reject) => {
const number = ++amount;
console.log(`Called number ${number}`);
setTimeout(() => {
console.log(`Resolved after one second number ${number}`);
resolve();
}, 1000);
})
);

emitter.emit("test");
emitter.emit("test");

console.log("I'm not waiting for the promises to resolve");
const EventEmitter = require("events");
const emitter = new EventEmitter();

let amount = 0;

emitter.on(
"test",
() =>
new Promise((resolve, reject) => {
const number = ++amount;
console.log(`Called number ${number}`);
setTimeout(() => {
console.log(`Resolved after one second number ${number}`);
resolve();
}, 1000);
})
);

emitter.emit("test");
emitter.emit("test");

console.log("I'm not waiting for the promises to resolve");
Want results from more Discord servers?
Add your server