well, the .send()
method returns the sent message in a promise.so if you want to id of a sent message, you can just do this:
let ID = await message.channel.send('message').id
this will send the message "message" then set the variable "ID" equal to the id of that sent message. Alternatively, you can omit the .id
entirely and instead it will set ID equal to the sent message object.
if you want to count the number of reactions on said message after a given amount of time, you can use setTimeout() to call a function after a set amount of time and have that function read the reaction manager of the previously sent message.
Does this make sense? do you need more help? feel free to ask more questions or dm me on discord @ Ravenr_#9014
See the following: https://hastebin.com/odonaqahad.js
You previously closed the message
event which you declare the message
variable and tried to use the message
variable outside of that scope.
(node:391) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'name' of undefined
(node:391) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli\_unhandled\_rejections\_mode). (rejection id: 1)
(node:391) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
I keep getting this error when the bots name changes
Yes this can easily be done using child_process.fork()
If you make an array of tokens then loop through them and add the token as a commandline argument, you can get it from inside your index file using process.argv and start the individual bots like that. This means all your bot instances share the same files.
>DananaBanana#0001
i get a:
(node:25) UnhandledPromiseRejectionWarning: Error: connect ECONNREFUSED 51.222.40.127:19132 at TCPConnectWrap.afterConnect as oncomplete(Use node --trace-warnings ...
to show where the warning was created)(node:25) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict
(see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)(node:25) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
error
Already tried it without return.
Anyways, copied your code, which I didn't need to since it's the same.
(node:28463) UnhandledPromiseRejectionWarning: DiscordAPIError: Missing Permissions
at RequestHandler.execute (/home/dreamerdog/dreamerdog/node_modules/discord.js/src/rest/RequestHandler.js:170:25)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:28463) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict
(see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:28463) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Ok, I got it working, it had nothing to do with warn.js, it was about warns.js and deleting that it got me an other problem
(node:531) UnhandledPromiseRejectionWarning: SyntaxError: Unexpected end of JSON input
at JSON.parse (<anonymous>)
at Object.execute (/home/runner/partioBot/commands/strike.js:10:24)
at Client.<anonymous> (/home/runner/partioBot/index.js:56:39)
at Client.emit (events.js:314:20)
at Client.EventEmitter.emit (domain.js:483:12)
at MessageCreateAction.handle (/home/runner/partioBot/node_modules/discord.js/src/client/actions/MessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (/home/runner/partioBot/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (/home/runner/partioBot/node_modules/discord.js/src/client/websocket/WebSocketManager.js:384:31)
at WebSocketShard.onPacket (/home/runner/partioBot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:444:22)
at WebSocketShard.onMessage (/home/runner/partioBot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:301:10)
(node:531) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:531) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Edit: I get such an error on my console:
(node:9848) UnhandledPromiseRejectionWarning: TypeError [INVALID_TYPE]: Supplied name is not a string.
at ClientPresence._parse (C:\Users\Eren\Desktop\hype\node_modules\discord.js\src\structures\ClientPresence.js:36:52)
at ClientPresence.set (C:\Users\Eren\Desktop\hype\node_modules\discord.js\src\structures\ClientPresence.js:18:31)
at ClientUser.setPresence (C:\Users\Eren\Desktop\hype\node_modules\discord.js\src\structures\ClientUser.js:114:33)
at ClientUser.setActivity (C:\Users\Eren\Desktop\hype\node_modules\discord.js\src\structures\ClientUser.js:165:17)
at Timeout._onTimeout (C:\Users\Eren\Desktop\hype\events\ready.js:27:17)
at listOnTimeout (internal/timers.js:549:17)
at processTimers (internal/timers.js:492:7)
(node:9848) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 48)
I'm getting an error with this code.
```(node:4862) UnhandledPromiseRejectionWarning: TypeError [INVALID_TYPE]: Supplied roles is not an Array or Collection of Roles or Snowflakes.
at GuildMemberRoleManager.add (/home/anlnrd/Documents/projects/fwa-bot/node_modules/discord.js/src/managers/GuildMemberRoleManager.js:85:15)
at /home/anlnrd/Documents/projects/fwa-bot/commands/role.js:62:39
at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:4862) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:4862) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. ```
Here's the source code in role.js around the line 62.
const guild = client.guilds.cache.get(guild_id);
const guildMember = guild.members.cache.get(message.author.id);
const role = guild.roles.cache.find(role => role.id === lifetime_role_id);
guildMember.roles.add([role]); // line 62
message.reply('Applied role');
I don't quite understand the issue, I'm using [role] so it should be an array... do you have any idea why I'm getting this error?
node -v
That should do the trick.
There is a function within the file-system (fs
) module called .watch(). https://nodejs.org/docs/latest-v10.x/api/fs.html#fs_fs_watch_filename_options_listener This method will watch for a change in a file..
Use this information as you may.
Hey,
You can use JSON-based point system and fs. Although this will only work if you have a command handler.
It may work if you just use a regular http
url without ssl, but there's 0 reason not to enable (and even ENFORCE - i.e. don't allow regular http access) SSL on your domain.
It's an easy setup and is otherwise automatic with something like certbot
No, the bot ran just fine until suddenly it quit running and threw the error "cannot find module Discord.JS". I reinstalled Discord.JS and now it's saying there's an error in client.js. I have no file named client.js. Therefore, I can only assume that the error is somewhere in the discord.js module. This has now happened on three of my bots, all that ran before hand. On top of that, I don't have a single "catch" in any of my bots.
I am running this on glitch.com, I went to a different bot that still ran, remixed it, and copy pasted the scripts from all these bots that no longer ran directly into the remixed project, and they ran. So it's not me, it's in the discord.js module.
No, the bot ran just fine until suddenly it quit running and threw the error "cannot find module Discord.JS". I reinstalled Discord.JS and now it's saying there's an error in client.js. I have no file named client.js. Therefore, I can only assume that the error is somewhere in the discord.js module. This has now happened on three of my bots, all that ran before hand. On top of that, I don't have a single "catch" in any of my bots.
I am running this on glitch.com, I went to a different bot that still ran, remixed it, and copy pasted the scripts from all these bots that no longer ran directly into the remixed project, and they ran. So it's not me, it's in the discord.js module.
No, the bot ran just fine until suddenly it quit running and threw the error "cannot find module Discord.JS". I reinstalled Discord.JS and now it's saying there's an error in client.js. I have no file named client.js. Therefore, I can only assume that the error is somewhere in the discord.js module. This has now happened on three of my bots, all that ran before hand. On top of that, I don't have a single "catch" in any of my bots.
I am running this on glitch.com, I went to a different bot that still ran, remixed it, and copy pasted the scripts from all these bots that no longer ran directly into the remixed project, and they ran. So it's not me, it's in the discord.js module.
No, the bot ran just fine until suddenly it quit running and threw the error "cannot find module Discord.JS". I reinstalled Discord.JS and now it's saying there's an error in client.js. I have no file named client.js. Therefore, I can only assume that the error is somewhere in the discord.js module. This has now happened on three of my bots, all that ran before hand. On top of that, I don't have a single "catch" in any of my bots.
I am running this on glitch.com, I went to a different bot that still ran, remixed it, and copy pasted the scripts from all these bots that no longer ran directly into the remixed project, and they ran. So it's not me, it's in the discord.js module.
>but I've since lost the code.
ALWAYS use source control! Never write a single line of code if it's not source controlled!
https://www.git-tower.com/learn/git/ebook/en/command-line/basics/why-use-version-control
(Version control == source control)
Since you're using typescript and you've got "declaration": true
in your tsconfig, tsc
should output type declarations *.d.ts
alongside your js files automatically. Now you just need to link them to the package by assigning the types
property in package.json
.
You can read more here: https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html
then set up a database i personally like mongodb, because they have a good free plan https://stackabuse.com/a-beginner-level-introduction-to-mongodb-with-node-js/ get a free tier here https://www.mongodb.com/cloud/atlas/
From the ones I've named, I'd pick either TypeORM or Prisma. The getting started guides for these are straight forward and their documentation is a bit more on the friendlier side of things.
If you aren't using one, how are you saving whether or not a user has certain commands enabled or disabled (such that restarting your bot doesn't get rid of the settings)? I assume you aren't.
That's the point of the example tasks I listed.
I'd seriously recommend giving these tasks a go as they will help you build some very relevant foundational skills for programming in general.
I'd recommend you use version 6 of Sequelize - the guide already suggests to use 5+ as 4 has a security vulnerability. Alternatively I'd recommend you use Prisma instead!
For folder structure, it's pretty much up to you, as long as your imports and requires are what they need to be.
database
folder, in there create the dbInit.js
, dbObjects.jsand
models` folder.If you extend the client class and give it a db
property, you can assign the Sequelize instance to it and then access your db with this.client.db
throughout.
The guide is using v4 which is outdated, I'm also a fan of the class based approach with Sequelize, this involves extending the Model class, passing in your options to the super constructor, and overriding the built in functions to setup associations, filters, etc. Unfortunately the documentation isn't that great - it's extensive and exhaustive, but it's hard to navigate and understand if you don't already know what you're looking at.