#development

1 messages · Page 1475 of 1

delicate shore
#

on ubuntu

#

v20

severe pendant
#

?

carmine shore
#

lil question

#

for bots and stuff, can 2 bots have slash commands of the same name?

#

if not then that just ruins it for me lmao

severe pendant
#

stars

#

Do u know how to fix

carmine shore
#

Well you're not importing the file properly, does it maybe not exist in that place @severe pendant

#

either way i dont use discord.js so idk

carmine shore
earnest phoenix
#

How to limit args? I forgot

#

I want to limit characters used after command

marble juniper
#

use the join method and then the length property

earnest phoenix
#

Aight

severe pendant
#

Anyone

carmine summit
#

It returns a map

#

I think

#

then it increases

#

I think

#

every time react

#

I THINK

quartz kindle
#

cwickks thinks he thinks

carmine summit
#

or just use client.on("reactionAdd")

#

I think

quartz kindle
#

awaitReactions only returns when it finishes running

#

you didnt specify a reaction limit, only a time limit

#

so it only returns after 6 seconds, and not when a person reacts

#

you also only use it once, after its done it stops listening

feral aspen
#

Question

eternal osprey
#

hey

feral aspen
#

In v12, to delete a message after certain amount of time, is it like this? ```js
const msg = await message.channel.send(createdAccount)
msg.delete(8000);

quartz kindle
eternal osprey
#
 if(message.content == "!cart"){
         
          var text = fs.readFileSync("./cart.txt").toString('utf-8');
console.log(text)
let text1 = text.split(/ +/g)
console.log(text1)
         if(message.author.id == text1[0]){

          message.channel.send(text1[2])
         ```` with this code i am trying to get all the contents text1[2] that have the same id as the author:
earnest phoenix
#

Ok

eternal osprey
earnest phoenix
#

@eternal osprey bro are you using a txt file for a database

eternal osprey
#

I always start with bases, later on going to migrate it to Atlas.

earnest phoenix
#

wdym

quartz kindle
#

fs.readFileSync("./cart.txt").toString('utf-8'); === fs.readFileSync("./cart.txt", "utf8"); lol

eternal osprey
#

i am trying to understand as much as possible of my code, so I first start with the basics (easy going with textfiles), later on with harder databases.

gloomy python
earnest phoenix
#

you're using it as a read only reference for later?

eternal osprey
#

i am trying to learn from my code, so i usually begin easy and later on go a level up in difficulty.

#

this is not a code for a bot that i am going to use, i am just trying to learn from it.

quartz kindle
#

each line is supposed to be an entry?

#

then you need to split by newlines, not by space

eternal osprey
#

wdym with newlines?

#

could you provide an example

quartz kindle
#

.split("\r\n") on windows

#

or \n on linux

eternal osprey
#

and what would that do?

quartz kindle
#

make an array of lines

eternal osprey
#

aha okay.

earnest phoenix
#

@quartz kindle or we could just do string.replace(/\\r\\n/g, "\n"); if we dunno the OS

quartz kindle
#

yes

eternal osprey
#

yeah i see, it returns 1.

#

but i am trying to split the id from the actual product name.

quartz kindle
#

yes, but that comes later

#

first you split by lines, so you have the entries correct

#

otherwise you get that mess

eternal osprey
quartz kindle
#

how did you split?

earnest phoenix
#

or use regex in the split if you don't trust yourself: / +/

quartz kindle
#

i would just do this fs.readFileSync(...).split("\r\n").map(x => x.split(/ +/))

earnest phoenix
#

||yeah baby im flexing my 1% regex knowledge||

#

@quartz kindle btw they're probably deploying their bot to a vps after coding and testing on their windows pc

quartz kindle
#

its gonna be the same if they upload the same text file

eternal osprey
#

I am not deploying it to my vps.

earnest phoenix
#

self hosting?

#

epic

eternal osprey
earnest phoenix
eternal osprey
#

it is just pure so i can learn from it, once again.

earnest phoenix
#

what

eternal osprey
earnest phoenix
#

you're developing a bot that you're never gonna use?

earnest phoenix
#

but... how are you greenname

eternal osprey
quartz kindle
#

let them learn lol

earnest phoenix
#

how to host the bot 😭

eternal osprey
eternal osprey
quartz kindle
#

8 is a lot

#

i pay 2.75

eternal osprey
#

what's the vps called ma guy.

quartz kindle
#

galaxygate

eternal osprey
#

yo i am switching up lmao.

earnest phoenix
#

i use repl.it digitalocean or google is a good vps too

eternal osprey
#

1gb ram?

quartz kindle
#

yes, i highly recommend google f1-micro for starters

#

yes thats the one i have

#

if you pay yearly, you get 1 month free

#

so it becomes 2.75/month

eternal osprey
#

is 1gb ram enough tho?

quartz kindle
#

it is for me

#

3 bots, an api and a website

eternal osprey
#

yeah i once made a website, I tried hosting it myself but it was running on a localhost server.

#

so i was told that i had to portforward through my internetprovider.

eternal osprey
quartz kindle
#

this is my average htop

eternal osprey
quartz kindle
#

its not

#

its using 413 out of 981

eternal osprey
#

owh i didn't see that.

#

hey this site actually has good plans for what you get.

#

thanks bro! Switching everything right now.

eternal osprey
#

would i basically call the different arrays using text1[0] and text1[1]

#

or..?

quartz kindle
#

unknown message

#

either the message is already deleted, or your bot cant see it for some reason

earnest phoenix
#

channel history perm maybe

feral aspen
#
premium.premium = true;
premium.premiumCooldown = Date.now()
premium.save().catch(err => console.log(err));

const embedThree = new Discord.MessageEmbed()
.setColor(colors.cyan)
.setDescription("You received your premium, thanks! 111")
                    
message.channel.send(embedThree)

setTimeout(function(){
   premium.premium = false;
   message.author.send("Your premium subscription has ended, you may re-subscribe by performing the `!redeem` command!")
}, ms(timeout))
glossy heath
#

hi

#

😭

feral aspen
#

I'm trying to make a function where after a few seconds let timeout = 15000, it will make the premium.premium = false, but it doesn't let me save twice, any help? premium.save().catch(err => console.log(err));

earnest phoenix
#

doesn't ms convert anything you pass to it to milliseconds

#

or

feral aspen
#

Yes 1 second is 1000

#

Oh.

#

Not sure.

earnest phoenix
#

try passing timeout directly, without using ms

feral aspen
#

But the function doesn't work unfortunately.

earnest phoenix
#

because you don't really need it in the first place

feral aspen
#
}, timeout)
#

Like this?

earnest phoenix
#

yes

#

so you were actually just passing a string to setTimeout

#

which it doesn't accept

feral aspen
#

I want it to save twice.

earnest phoenix
#

but you're not saving twice anywhere

#

you're saving only once

feral aspen
#

When the user gets the premium, it makes premium = true, after amount of time finishes which is 15 seconds, it will go back to false until he performs the command again

earnest phoenix
#

the function in setTimeout never executes

#

you also don't save in setTimeout

feral aspen
#

How can I make it set it to false after a few seconds, well that is not going to happen as it will be after a month where it changes.

earnest phoenix
#

🙄 have you been ignoring everything i've been saying to you

feral aspen
#

Yes, I am reading.

earnest phoenix
#

setTimeout doesn't work for long periods of time and you shouldn't really use it for long periods of time

#

in case of downtime

feral aspen
earnest phoenix
#

save the date of expiry in a database in unix

on boot pull every date out of your database and create a setInterval that loops and checks whether any date is past the current one

#

when you need to add a new date, add it to both your database and your memory

feral aspen
#

Like every January and such?

#

But that will give the premium user more time than usual.

#

Making it unfair.

earnest phoenix
#

w h a t

#

please

#

either you're skim reading or you're not understanding what i'm saying

#

or both

feral aspen
#

... I just take time to understand.

earnest phoenix
#

lets try pseudo code instead

delicate shore
#

hi ok so

vale garden
#

yo

#

asking this question for the 9th time, but can i code for an oauth2 app and bot in the same file

#

im really dumb plz help me out

#

lmfao

delicate shore
#

I mean , if you wanna make your life miserable
Sure ! Go ahead

vale garden
#

lol

#

the thing is i cant use different files for it

#

coz i have info in a json file which i gotta use for the bot

#

and im on repl so that means i have to create a new repl

earnest phoenix
#
//this part exists somewhere outside, in your main file or whatever
//map keyed by user id and stores your database values
new Map();
//interval loops every second checking if anything had expired
setInterval(() => {
  //filter map so you get values where the stored date is smaller than Date.now(),
  //it means it expired

  //if you have any values from the filter, remove them from the map
  //and from the database
}, 1000);

//this should ONLY run on application boot
let allOfMyDatabaseValues = await fetchAllValues();
for(let value of allOfMmyDatabaseValues)
  value.put(value.userId, value.expiry);

//your premium command thingy or whatever it is
databaseobject.expiry = Date.now() + the duration of premium in milliseconds
save();

@feral aspen this is pseudo code

earnest phoenix
vale garden
#

it does

earnest phoenix
#

no it does not

vale garden
#

see

#

you have a discord app

#

with the identity and bot scopes ticked

#

and

earnest phoenix
#

creating an oauth2 app and implementing discord oauth2 are two entirely different things

vale garden
#

ah what

misty sigil
#

and one is much harder

vale garden
#

yea ok

earnest phoenix
#

oauth2 is not something tied to discord lol

vale garden
#

but the thing is

misty sigil
vale garden
#

ik but

#

yea ik that

#

i mean

#

i have the code for the oauth2

#

but

#

i also need that app to function as a bot

earnest phoenix
#

so... do that?

misty sigil
#

use a web server

vale garden
#

so i will require code for the oauth2 and the bot

#

and like

misty sigil
#

inside of your bot files

#

??

vale garden
#

i cant just put both the code

#

wat

misty sigil
#

yes??

#

you can??

vale garden
#

wa

#

how

earnest phoenix
#

by just putting it lol

vale garden
#

i mean like i just stacked the codes on top of each other

#

and then whichever is above gets executed

earnest phoenix
#

your bot is not the application itself
your webserver is not the application itself

vale garden
#

ik both of them together are

#

right?

earnest phoenix
#

incorrect

#

that is everything that's inside of your application

#

however they're not the application itself

#

your application can work without the bot, without the webserver

vale garden
#

oh you mean it like that

#

yea ok but that doesnt matter lol

#

so i just code chilling like this

#
from datetime import date
from flask import Flask, request, redirect
from oauth import Oauth
from tinydb import TinyDB, Query

db = TinyDB('./db.json')
User = Query()

app = Flask(__name__)

@app.route("/", methods = ['get'])
def index():
  return redirect(Oauth.discord_login_url)
  
@app.route("/login", methods = ['get'])

def login():
  #Code Here..

if (__name__ == "__main__"):
  app.run(debug = True, host = '0.0.0.0', port = 5000)

bot = commands.Bot(command_prefix = "!")

@bot.event
async def on_ready():
  print("yo")

#Commands Here..

bot.run(os.environ.get("TOKEN"))  
#

anddddd

#

since the oauth2 stuff is above only that works

misty sigil
#

json db.................

vale garden
#

P.S ik this might be extremely wrong

#

or whatever

#

wha

#

bruh its just simple stuff to store it isnt much

#

so doesnt matter

#

lol

misty sigil
#

so in /login you wanna get the query (code)

vale garden
#

ye

misty sigil
#

as discord redirects to /login?code=OAUTHCode

vale garden
#

yep

misty sigil
#

and you make a few fetch requests

#

i can’t exactly recall where to atm

vale garden
#

that doesnt matter bruh

#

i just need the bot code to work as well

#

but idk how to

#

oof

#

i mean the codes are working fine alone

#

but i need them to function simultaneously

#

which is the issue i have

eternal osprey
#

now i have a different question. My split functions etc worked great, but how do i do this with all the string that have the same author id?

#

as you can see i am cmparing the author ids, but how would i do this for all the string in the textfile?

summer acorn
#

you can use the Array.some() method

#

example; Array.some(id => message.author.id === id)

#

it will check for if message.author.id is equal to any of the items in the array

#

in our case, we call them an id

eternal osprey
#

so i should remove the if

eternal osprey
summer acorn
#

because that is what we want to do

#

no you put the Array.some inside the if statement

eternal osprey
#

aha oaky

summer acorn
#

and then you gotta replace Array with the variable name of the array or simple just an array like [1,2,3,4,5,6,7,8,9,0]

eternal osprey
#

for me it is text2[0[ i guess

#

because that holds all the ids

summer acorn
#

that depends on it text2[0] is an array

#

if text2 is the array with the ids, you gotta use text2.some

#

if you have an array at index 0 containing the ids, inside of text2, you gotta do text2[0].some

eternal osprey
#

text2[0].some is not a function

#
 if(message.content == "!cart"){
          var text = fs.readFileSync("./cart.txt").toString('utf-8');
          
let text1 = text.split("\r\n")
let text2 = text1[0].split(/ +/g)
console.log(text2[1])
if(text2[0].some(id => (message.author.id == text2[0]))){
  
  

          message.channel.send(text2[1])
         


         }

         

        }```
summer acorn
#

is text2[0] an array?

#

based of that code, it is not\

eternal osprey
#

it is a string..

#

fuck

#

sorry.

summer acorn
#

try text2.some then

eternal osprey
#

oaky so it worked

#

but as soon as more things are in the text file:

#

345138133429649408 2K2RKit
345138133429649408 AxuasKit
345138133429649408 FlyKit

#

it returns only this: 2K2RKit
345138133429649408

#

so it doesn't get all the items in the text file

#

only the first one.

#

@summer acorn

summer acorn
#

You could try using a json file, you won't need to split in that and it'll be a lot simpler

eternal osprey
summer acorn
#

you simply just do

var adminIds = require('./admins.json'); // assuming these people are your admins

console.log(adminIds); // ["345138133429649408", "345138133429649408", "345138133429649408"]

if (adminIds.some(/*query*/)) {
    // code
}
#

the json file will just be

["345138133429649408", "345138133429649408", "345138133429649408"]
earnest phoenix
#

hii guys i need help of a developer who uses java

summer acorn
#

a JSON file is like an object

eternal osprey
#

345138133429649408 2K2RKit
345138133429649408 AxuasKit
345138133429649408 FlyKit

earnest phoenix
#

anyone knows?

eternal osprey
#

i am basically checking the id with the message.authoer.

earnest phoenix
#

or anyone can help me?

eternal osprey
#

then i want its text behind the id.

earnest phoenix
#

what about

{
  "345138133429649408": "2K2RKit",
  "345138133429649408": "AxuasKit"
}
#

something like that

summer acorn
#

then you can do

[["345138133429649408", "2K2RKit"],
["345138133429649408", "AxuasKit"],
["345138133429649408", "FlyKit"]]
if (adminIds.some(id => message.author.id === id[0])) {/*code*/}
earnest phoenix
#

no one helping me

#

kek, don't ask to ask

#

@unkempt ocean no one helping or telling me here

#

what to do

eternal osprey
earnest phoenix
heavy anchor
#

Smh

quartz kindle
eternal osprey
earnest phoenix
#

i need hel of a java developer or someone who knows java @eternal osprey

eternal osprey
#

s o that's why i asked how to take them all

quartz kindle
#

nobody is gonna say "i know, what is the question"

#

everyone is waiting for what the question is

earnest phoenix
#

i need a code which brings bot online the one i watched on yt showing errors even i am typing the same

quartz kindle
eternal osprey
#

we can't respond within 1 second

earnest phoenix
#

sry

earnest phoenix
#

package mainPackage;

import javax.security.auth.login.LoginException;

import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.OnlineStatus;
import net.dv8tion.jda.core.entities.Game;
import techtoolbox.Bot.events.GuildMessageReceived;

public class Main {
public static String prefix = "~";

public static void main(String[] args) throws LoginException {
    JDABuilder builder = new JDABuilder();
    builder.setToken("Your token goes here.");
    builder.setStatus(OnlineStatus.ONLINE);
    builder.setGame(Game.playing("boring comedy shows."));

    // Register listeners
    builder.addEventListener(new GuildMessageReceived());

    builder.build();
}

}

eternal osprey
earnest phoenix
#

i am addint token but still

#

cant show u token right

quartz kindle
#

you are only using the first item, and then asking why its not finding the other items lol

eternal osprey
#

but how would i get all the available items then?

earnest phoenix
#

just not gettin this error

#

Multiple markers at this line
- The value of the local variable builder is
not used

quartz kindle
#

@earnest phoenix JDA has a full example in its repository which you can check

earnest phoenix
#

oo ty

eternal osprey
#
var text = fs.readFileSync("./cart.txt").toString('utf-8');
          
let text1 = text.split("\r\n")```
#

it is reading the whole file?

#

so getting all the products.

quartz kindle
#

yes, text1 has all products

#

but once you do text1[0] thats no longer all products, its only the first one

#

and you're searching inside text2, which is text1[0]

#

you have to search in text1, not text1[0]

#

its much easier if you pre-split all items, like i showed you before

quartz kindle
#

allItems = fs.readFileSync("./cart.txt", "utf8").split("\r\n").map(x => x.split(/ +/))

eternal osprey
#

and how would i access the different strings? AllItems[0] right/ and allitems[1]

#

as you are splitting them

#

this doesn't seem to be working

mellow kelp
#

newlines are hella confusing

eternal osprey
#

and i don't even know how much products it contains

mellow kelp
#

sometimes they are \n and sometimes they are \r\n

eternal osprey
#

it cvan be ranging from 6 to 22

#

@quartz kindle

rocky hearth
#

how to create an immutable array in js/ts?

mellow kelp
#

Object.freeze

#

i think so

rocky hearth
#

ok, how to let ts know about it?

mellow kelp
#

wat

#

um

#

panik

rocky hearth
#

so it wont suggest the push and pop method on that array

quartz kindle
mellow kelp
#

well push and pop are always suggested

#

they're methods

quartz kindle
#

did you save the file using code?

#

because if you save it using notepad, windows automatically adds \r\n

eternal osprey
quartz kindle
#

but if you save it using code with only \n then it will only have \n

#

so now you have to split using \n not \r\n

rocky hearth
mellow kelp
#

o

#

epik

#

and i just checked

#

Object.freeze uses generics so there ya go

eternal osprey
#

but @quartz kindle

#

the problem is, is that I don't know how much products it contains

quartz kindle
#

just do .split(/\r\n|\r|\n/) to account for both lol

eternal osprey
#

right now there are only 4 arrays.

#

but some other time there micht be 6

quartz kindle
#

doesnt matter

#

you're effectively creating a table

#

with unlimited number of rows and columns

#

the first array is rows, the array inside it is columns

eternal osprey
#

hmm okay

quartz kindle
#

you might want to remove empty lines tho, it seems like your file has an empty line at the end

eternal osprey
#

but how would i seperately call the first array, and the second?

quartz kindle
#

.split(/\r\n|\r|\n/).filter(Boolean).map(...)

eternal osprey
quartz kindle
#

items[row number][column number]

#

items[2][1] = data of 3rd item, items[5][0] = id of 6th item

eternal osprey
#

but that's the problem..

#

i don't know how much items it contains

#

so i can't just take a rough guess.

#

i might add 3 products, tomorrow i might add 0 products.

#

so the rows and the columns change each time.

quartz kindle
#

it doesnt matter

#

its just a matter of how you want to search it

eternal osprey
#

how doesn't it matter if i don't know what to call?

quartz kindle
#

the table is just a storage system, you decide how you want to use it

#

give me an example of how you want to find something in it

eternal osprey
#

okay let me explain it.

#

you can add products to your cart (the text file)

#

using !product(number)

#

for example !product2

#

it will save your id + the productname

#

later on there might be 9 products in your cart

#

you type !cart

#

and it will display all product names that match your id.

quartz kindle
#

items.filter(item => item[0] === id)

cinder patio
#

And why are you storing all that in a plain text file and not a database? Even json would be better than plain text

eternal osprey
#

i first start the base using text

#

then over to database.

cinder patio
#

that's just a huge waste of time because you wouldn't be here asking these questions if you just started with a database... but sure okay

reef dawn
#

hello my friends, is there anyone to help me?

eternal osprey
reef dawn
#

My bot is approved but I was not on the server then what should I do?

quartz kindle
#

(dont ping all mods)

quartz kindle
#

do you not know about array.filter?

eternal osprey
#

but the problem here is.... i still don't understand the column shit etc.

quartz kindle
#
[
  [a1,b1,c1]
  [a2,b2,c2]
  [a3,b3,c3]
]
``` this is how your data looks like after splitting
eternal osprey
#

yeah

quartz kindle
#

items[0] = [a1,b1,c1]

#

items[0][0] = a1

eternal osprey
#

allItems*

quartz kindle
#

yes

eternal osprey
#

okay yeah i got that

#

but i have 23 products, so how in hell am i gonna know how much products someone addst o

quartz kindle
#

items.filter(x => x[0] === a1) = [a1,b1,c1]

#

^ filter all items, return those where the first value of it matches the value you want

#

lets say you have this

#
964958734589 someproduct
964958734589 someproduct2
964958734589 someproduct3
964952563455 someproduct
#

thats 1 person with 3 products, another person with 1 product

#

after splitting, you have this ```js
[
[964958734589, someproduct]
[964958734589, someproduct2]
[964958734589, someproduct3]
[964952563455, someproduct]
]

eternal osprey
#

yeah

#

I understand this part.

misty sigil
#

array of arrays

quartz kindle
#
items.filter(item => item[0] === 964958734589)
/*
[
  [964958734589, someproduct]
  [964958734589, someproduct2]
  [964958734589, someproduct3]
]
*/
misty sigil
#

there’s just something funny about that

eternal osprey
#
allItems.filter(x => x[0] === message.author.id) ```
#

i used this

quartz kindle
#

yes

eternal osprey
#

and later on message.channel.send(allItems)

quartz kindle
#

no

#

the filtered array is returned as a value

#

the original array is not modified

eternal osprey
#

owh okay

#

yeah

quartz kindle
#

let filtered = allitems.filter()

eternal osprey
#

ofc you have to define a variable to it

quartz kindle
#

also, filtered is an array of arrays, just like allItems, but it only contains the entries that match the id

#

you cant send it as a message directly

#

either stringify it, or extract the values you want

#

for example, to get a list of product names

#

filtered.map(x => x[1]).join("\n")

eternal osprey
quartz kindle
#

with the code above```js
[
[964958734589, someproduct]
[964958734589, someproduct2]
[964958734589, someproduct3]
]
becomes
[
someproduct
someproduct2
someproduct3
]
and then becomes
someproduct someproduct2 someproduct3

#

the final value after joining is a string, so you can safely send it

eternal osprey
#

yeah exactly

#

it works, thanks!

#

I understand it now.

#

is it okay if i copy this conversation into my learn folder?

#

so i can later on have a better look>

#

if you have any problems with that, ping me and i'll delete the convo.

earnest phoenix
#

@quartz kindle i did that code now what i need to do for my bot to come online

#

bot will come online when i host or what i am new really

#

not have much knowledge

feral aspen
#

Is there really no actual way to convert things like

{
    "test": "${message.author.username} is a username."
}```

to actual stuff like this?

```js
const embed = new Discord.MessageEmbed()
    .setColor(colors.cyan)
    .setDescription(permissions.test)

    return message.channel.send(embed)

It just sends ${message.author.username} instead of sending the username of the author! 😆

earnest phoenix
#

that is still treated as a string

#

you cannot take a random string and treat it as code

misty sigil
#

could you replace it?

earnest phoenix
#

manipulate the string to include your variable

#

yeah

misty sigil
#

.replace('username', message.author.username)

feral aspen
#

Or*, should I manually edit the .setDescription() part?

#

Would take a lot of time..

earnest phoenix
quartz kindle
#

you can add placeholders

#

for example ```js
string = "ououg weughowuehwgh ou %%USERNAME%% ouhowuehowute"
string.replace("%%USERNAME%%", message.author.username)

feral aspen
#

Oh

earnest phoenix
#

french 😍

quartz kindle
#

wat

earnest phoenix
#

i was kidding

feral aspen
#
.setDescription(permissions.test.replace("username", message,author.username))
quartz kindle
#

lmao

feral aspen
#

Like that?

misty sigil
quartz kindle
#

yes, but it has to be a placeholder that you're sure it will never be used as a normal text

#

so you dont accidentally replace things that you dont want to replace

quartz kindle
#

if your code works, it should become online as soon as you run the program

#

it will only be online while the program is running

earnest phoenix
#

alr

#

ty

feral aspen
quartz kindle
#

for example

#
string = "to change your username run /username newname"
#

if you do .replace("username") on that, it will replace things you dont want to replace

feral aspen
#

Yes, so I can put some type of sign near the thing I want to replace, right?

quartz kindle
#

yes

feral aspen
#

Thank you! 🙂

#

Thank you for the information!

shut spear
#

only bot's reaction is seen on messageReactionAdd event but no any other user reactions, any fix or explanation about this?

client.on('ready', () => {
   react(client);
});

function react(client){    
    var channel=client.channels.cache.get('channel-id');
    channel.messages.fetch('message-id')
       .then(message =>{
           message.react("🇬🇧");
       })
}

client.on('messageReactionAdd', (reaction, user) => {
    console.log("a user just reacted");
});
quartz kindle
#

are you using intents?

#

are you reacting on an old message that already existed before the bot started? or a new message sent after the bot started?

shut spear
#

old, existed before bot started

quartz kindle
#

you need to enable partials for that

shut spear
#

already 🙁

quartz kindle
#

show client options

shut spear
#

var client = new Discord.Client({ partials: ['MESSAGE', 'CHANNEL', 'REACTION'] });

quartz kindle
#

needs USER too

shut spear
#

ty so much!

crimson vapor
#

how would I cache mongoose?

#

like queries

#

I can query for more than just _id so idk how I would cache the objects with a key

#

I could cache one big map but that seems inefficient

past needle
#

(node:27) UnhandledPromiseRejectionWarning: DiscordjsError: Request to use token, but token was unavailable to the client

#

q-p

#

please what this mean

#

why doesn't it work in the hoster website but it does if i run it in my terminal >_>

mellow kelp
#

probably means your bot is not logged in

crimson vapor
past needle
#

config

#

.json

crimson vapor
#

make sure token is defined

past needle
#

token is directly on the main file

misty sigil
#

I don’t use either I use info.json

crimson vapor
#

smh info.json

#

maybe for well info

#

but not configuration shit

crimson vapor
past needle
#

:o

#

wdym harcoded

crimson vapor
#

like a constant

#

never changes

quartz kindle
#

token unavailable also happens if you remove the token after the bot starts

#

for example client.token = null

crimson vapor
#

oh

past needle
#

:o

#

i didn't anywhere

quartz kindle
#

show your code

past needle
#

pretty long code

#

300~ lignes for the index.js

crimson vapor
#

how many other files KEKW

past needle
#

where i put all the fast events like shardReady, ratelimit, error etc..

#

i'll try to console.log the token before it starts see if there is a problem

crimson vapor
#

most people make an event handler for that

past needle
#

yea i did only for the long coding events

#

like

#

channelCreate

#

but for those where i just need ton log something it's faster to make it to index.js

#

instead of an entire file for it

quartz kindle
#

just put it in a bin

#

pastebin hastebin codebin etc

crimson vapor
#

Tim do you know how I should cache mongoose?

past needle
#

alright

#

i'll try

weary widget
#

I need help with the snipe command i'm making, every time i use the command it sends it twice. if there is something to snipe, it will send the message and the error if there is nothing to send it will send the error twice

misty sigil
#

why store in txt files

crimson vapor
misty sigil
#

instead of memory

weary widget
#

what

crimson vapor
#

yeah cache it

weary widget
#

wait you can do that

crimson vapor
#

yes

weary widget
#

is it server specific?

crimson vapor
#

caching is not specific to anything except process

weary widget
#

hmm

#

I guess

#

but is there still a way to fix the problem i have currently?

past needle
#

lmfao

#

i just discovered that

#

whne doing client.destroy it will still listen to the events and all @crimson vapor @quartz kindle

#

q-q

#

this is why my bot's can't connect

crimson vapor
#

why did you use client.destroy?

#

all it does is kill the client

#

not very good for shutdown

slender thistle
#

Deb, make sure you're not running two instances of your bot

quartz kindle
#

client.destroy is a joke

#

it doesnt even work correctly

crimson vapor
#

yea

past needle
#

and if one didn't then it will crash the bot

crimson vapor
#

hmm

past needle
#

i should of used process.exit

#

ig

crimson vapor
#

use process.exit()

past needle
#

yup

#

thanks

crimson vapor
#

whats the best way to clean text of anything that can't be in a url

lyric mountain
#

In js idk, but there's probably some lib to encode to url

#

Maybe even vanilla

mellow kelp
#

in js its encodeURIComponent

#

vanilla js

crimson vapor
#

probably lemme check

earnest phoenix
#

What to do

crimson vapor
#

what do you mean?

earnest phoenix
#

@crimson vapor it's blank my workspace disappeared

crimson vapor
#

open the folder?

earnest phoenix
#

I opened

#

Lemme restart my computer

#

Maybe some other problem

#

BTW which language u use?

crimson vapor
#

it looks to me like you have it closed

#

I use js but know a but of java

earnest phoenix
#

Ic may I take help from u when I need

#

I am new

#

And yes problem solved ty

#

💪😄👌

#

@crimson vapor tell me

mellow kelp
#

ah yes

mellow kelp
crimson vapor
#

probably but idk much java

earnest phoenix
#

i have to rework my help command :/

shut spear
#

guild.members.cache only has bot as guildmember, not users who react. Any fixes?

client.on('messageReactionAdd', (reaction, user) => {
    if (emoji.name == '🇬🇧') {
        reaction.message.guild.fetch(user.id).then(async guild => {
            await guild.members.cache.get(user.id).roles.add('791237803622793227');
        });
    }
});
crimson vapor
#

fetch the user

#

also cache.get is not async

shut spear
#

its fetching?

#

reaction.message.guild.fetch(user.id).then(....

earnest phoenix
#

you're calling fetch on a guild object

#

oh

#

yeah

#

that will fetch the guild, and also doesn't take any args

#

not the user

#

wtf are you trying to do there

tribal siren
#

how do i send them the screenshots now?

earnest phoenix
#

...reply to the email?

shut spear
earnest phoenix
#

fetch needs to be empty

#

fetch is a promise so you need to await it

#

and then you can do your .roles.add

crystal wigeon
#

Is there an event triggered when a bot sent message is deleted?

#

Manually

mellow kelp
#

use the messageDelete event

#

and check the message author

sterile lantern
#

idk how to use the includes function with args

#

so i want to make it so if args[0] includes jobchoices

#

jobchoices = ["job1", "job2", "job3", "job4"];

crimson vapor
#

jobchoices.includes(args[0])

sterile lantern
#
  db.set(`job_${user.id}`, "Programmer")
  message.channel.send("You have now set your job as a Programmer! Salary: 100-150 coins every time you work." ) 
  elseif(args[0] === "Technican" || (args[0]) == "Technician")
  db.set (`job_${user.id}`, "Technician")
  message.channel.send("You have now set your job as a Technician! Salary: 110-175 coins every time you work.")```

elseif doesnt work here but regardless of elseif it sends both msgs and ignores the *if(args)*
quartz kindle
#

there must be a space between else and if

fossil birch
#

its elif

crimson vapor
#

yikes I prefer to use arrays and .includes rather than chaining if statements

quartz kindle
#

and if requires brackets

crimson vapor
#

no elif in js

mortal orchid
#

Its else if

#

Space required

fossil birch
#

oh

sterile lantern
#

i already have else

quartz kindle
#

it requires brackets

sterile lantern
#

o

mortal orchid
#

Yep

sterile lantern
#

else { function here
}

#

?

quartz kindle
#
// works
if(bla) something

// works
if(bla)
  something

// works
if(bla) {
  something
}

// does not work
if(bla)
  something;
  somethingElse;

// works
if(bla) {
  something;
  somethingElse
}
#

you can omit the brackets only for single lines

crimson vapor
#

the 4th one is just py

quartz kindle
#

py is weird

sterile lantern
#

eh i have a really messy job command

#

so basically, if they dont specify args it tells them what jobs they can choose

mellow kelp
sterile lantern
#

if they dont specify a valid job, it also sends that embed

#

but it completely ignores this:

#

if(args[0] == "Programmer" || (args[0]) == "programmer")

#

n v m

#

i forgot brackets lol

mellow kelp
#

lmao

#

and use === instead of ==

quartz kindle
#

you dont need () in the second one

#

btw you can replace that entire thing with this

#

if(args[0].toLowerCase() === "programmer")

#

actually, you can replace your entire code with an array or object of jobs lol

sterile lantern
#

oh wait

#

i can just do

#

if(args[0].toLowerCase() == jobchoices)

#

db.set("theirjob", args[0])

#

ez

#

but

#

i want it to be capitalized in the db

#

so like

#

Technician

#

instead of technician

quartz kindle
#
const jobs = ["Programmer","Technician","Engineer"];
let job = jobs.find(j => j.toLowerCase() === args[0].toLowerCase());
if(!job) return message.channel.send("invalid job")
db.set(..., job);
message.channel.send(`your job is now ${job}`)
sterile lantern
#

hm

#

ok

#

maybe ill just do toUpperCase

#

but then thatd make everything

#

uppercase

#

oof

quartz kindle
#

my code already does what you want

#

job is still uppercase

#

you convert it to lowercase only for the comparison

#

once its found, the original uppercase value is returned

sterile lantern
#

o

#

ok

#

this is 1 hour in millseconds

#

right

#

1000 * 60 * 120;

#

and then 2 hours would be 1000 * 60 * 180 right

earnest phoenix
#

does anyone know any bots that can give everybody in the server one role

mellow kelp
#

i think one hour in ms is 1 * 60 * 60 * 1000

sterile lantern
#

100 * 60 * 180 gives me this

#

it doesnt go to 2 hours for some reason

mellow kelp
#

o

sterile lantern
#

?role all +rolehere

quartz kindle
#

one hour is 1000 * 60 * 60

#

2 hours is 120

sterile lantern
#

mhm

#

i tried 120

quartz kindle
#

180 is 3 hours

sterile lantern
#

it givesme 59m when i try again

#

gives*

#

let timeout = 1000 * 60 * 120; //

#

i tried 1000 * 120 * 60

#

still gives me 59m 58s

#

ah wait a minute

earnest phoenix
#

order of multiplying does not matter

sterile lantern
#

im not printing the hours

earnest phoenix
#

are you leaving out the

sterile lantern
earnest phoenix
#

yeah

sterile lantern
#

yeah ok it worked

#

tyyy

earnest phoenix
mellow kelp
#

meth

sterile lantern
#

nah i thought it would be 180

#

because it wasnt printing hours

#

i had 120 at first

earnest phoenix
#

one hour in seconds is 60 * 60
a millisecond is a thousand times bigger so 1000 * 60 * 60
two hours is 2 * 1000 * 60 * 60

sterile lantern
#

but i forgot to print hours

#

so i thought is 1 hr

#

yea

earnest phoenix
sterile lantern
#

wat was that

#

a link?

earnest phoenix
#

THESE FUCKING ADVERTISERS DESERVE TO DIE IN THE LAVA PIT ON POLUS

#

moment is bloat

stable eagle
earnest phoenix
#

@stable eagle The "no oxygen" in space in skeld: Yes I am actually a joke

feral aspen
#
const { authorData } = require("../../permissions.json")
.setDescription(authorData)
#

Cry, it doesn't let me send the string in that json file.

#

It keeps sending ```js
null

mellow kelp
#

full code?

#

and whats in the json file

feral aspen
#
{
  "authorData": "❌ You do not have an economy account, be sure to create one by performing the **`!register`** command.",
}
mellow kelp
#

and whats the code

earnest phoenix
#

you sure you got the right directory?

#

nm

#

it would throw an error

feral aspen
#
if(!authorData) {
            const noAccount = new MessageEmbed()
            .setColor(red)
            .setDescription(authorData)

            return message.channel.send(noAccount)
        }
#

Instead of sending the string, it sends null! 🤷‍♂️

#

I mean

#

null

#

wtf

#

When it is const permissions = require("../../permissions.json"), it work, but if const { authorData } = require("../../permissions.json") it doesn't......

#

Why that.

#

oh fuk, authordata is already defined

#

🤦‍♂️

sterile lantern
#

devid is defined as my user ID,

how come ${devid.user} prints undefined

#

nvm i needed to fetch

earnest phoenix
#

Hey, I'm pretty new to Regular Expressions. And i made a simple regex which should detect something like this (random:1=10); and then generate a random number but for some reason it only returns one match even tho i have several matches in my string.

mellow kelp
#

idk if this might be the problem but

#

instead of using the regex constructor

#

just use /your-regex/flags

earnest phoenix
#

i tried that too

#

same results

mellow kelp
#

well apart from the problem just use that

#

but um

#

oh

#

it has a $ at the end

#

so it's only going to match if the expression is at the end of the string

earnest phoenix
#

OH

#

I wanted it to only detect the ones that end with an ;

#

how can i do that 👀

mellow kelp
#

you mean lines?

#

like

#

lines that end with ;?

earnest phoenix
#

wait let me give you an example

mellow kelp
#

k

earnest phoenix
#

This will work: (random:1=10);. This shouldn't be detected: (random:1=10)

mellow kelp
#

well you're already doing that

#

with the ;

#

i mean \;

earnest phoenix
#

oh so the $ isn't needed?

mellow kelp
#

nope

earnest phoenix
#

Ohh, ok let me try

mellow kelp
#

ight

earnest phoenix
mellow kelp
#

np

mellow kelp
#

just to keep the thing clean

earnest phoenix
#

Ok 👍

sterile lantern
#

how do you a fetch user in v12

#

last time i did was v11

#

is it client.cache.users.fetchUser

#

doubt thatd work

#

ah wait nvm its client.users.fetch

#
const dev = client.users.cache.get(devid) || await client.users.fetch(devid);```
#

how come dev is still undefined??

#

dev.user that is

#

nvm we dont need .user

#

``` .setThumbnail(${client.displayAvatarURL})

#

why does this not work

#

nvm i forgot .user and ()

quaint vault
#

Can you send me autorol commands? I'm on the phone but

lyric mountain
#

There's no "autorole commands", you need to write it yourself

sterile lantern
#

var date = (today.getMonth()+1)+'-'+today.getDate()+'-'+today.getFullYear();

#

is there a way to get minues

#

from today.

#

time*

#

so like 12-23-2020@1:10 PM EST

#

thats what i want it to print

#

currently only prints 12-23-2020

earnest phoenix
#

hi

#

how can i put 24/7 my bot

#

i use glitch

sterile lantern
#

buy a vps

#

glitch banned pinging services

earnest phoenix
#

buy?

sterile lantern
#

so you can't host on glitch

earnest phoenix
#

okay

sterile lantern
#

:)

earnest phoenix
#

when i delete the message by clicking the reaction, it gives the console this error.

(node:15508) UnhandledPromiseRejectionWarning: DiscordAPIError: Unknown Message
molten yarrow
sterile lantern
#

?

#

whats that

sterile lantern
#

so it doesn't know which message to delete

#

(i think)

#

or there is no message

#

hm

earnest phoenix
#

no let msg = await message.channel.send(${message.author}, embed);

sterile lantern
#

not sure

#

ah found the Intl.DateTimeFormat

#

thanks

molten yarrow
sterile lantern
#

yea i saw that

#

but how would i make it print

#

"Dec 23 2020, 01:16:10"

#

something like that

#

01:16 is EST timezone

molten yarrow
#

change en-GB?

#
new Intl.DateTimeFormat('en-US', { dateStyle: 'medium', timeStyle: 'medium' }).format(Date.now())

> "Dec 23, 2020, 7:16:40 PM"

sterile lantern
#

that prints as UTC

#

or not utc im not sure what the time zone is

vagrant vale
#

a

sterile lantern
#

but its 5 hrs ahead

#

of my time

#

so i want it my time

mellow kelp
#

we got a spammer here

molten yarrow
earnest phoenix
#

@sterile lantern ```js
function formatDate(dateVal) {
var newDate = new Date(dateVal);
var sMonth = padValue(newDate.getMonth() + 1);
var sDay = padValue(newDate.getDate());
var sYear = newDate.getFullYear();
var sHour = newDate.getHours();
var sMinute = padValue(newDate.getMinutes());
var sAMPM = "AM";
var iHourCheck = parseInt(sHour);
if (iHourCheck > 12) {
sAMPM = "PM";
sHour = iHourCheck - 12;
} else if (iHourCheck === 0) {
sHour = "12";
}
sHour = padValue(sHour);
return sMonth + "-" + sDay + "-" + sYear + " " + sHour + ":" + sMinute + " " + sAMPM;
}

function padValue(value) {
return (value < 10) ? "0" + value : value;
}


`formatDate("Wed May 27 10:35:00 EDT 2015")` return "05-27-2015 10:35 AM"
sterile lantern
#

woah thats a ton of code

#

i dont think that'd be a smart thing to do in a stats cmd

earnest phoenix
#

then you have to use moment.js

sterile lantern
#

is it called ET

#

idk

molten yarrow
#

whats your timezone?

sterile lantern
#

est

#

eastern standard time

earnest phoenix
molten yarrow
#

i mean add timeZone: 'America/New_York' if u from NY

sterile lantern
#

how did you know ok

eternal osprey
#

hey @polar flower I actually had a question pending but it didn't send it.

molten yarrow
#

you dont need other packages... @earnest phoenix

sterile lantern
#

ok it works tysm! <3

eternal osprey
#
collector.on('collect', (reaction, user) => {
                 message.channel.send("Okay, the cart is being cleared!")
                var cleared =  allItems.replace(final, '')
                fs.writeFileSync('cart.txt', cleared, 'utf-8');``` this somehow returns: allItems.replace is not a function
earnest phoenix
#

what is allItems

eternal osprey
#

I am basically trying to remove the final if someone actually stops the order.

#

just a text file with some products.

#

anyone that can tell what's the problem?

molten yarrow
#

is allItems a string?

eternal osprey
#

pff no.

molten yarrow
#

how u using .replace on it?

cinder patio
#

Obviously allItems is not a string, console.log it to see what it actually is.

eternal osprey
#

it's an array ofc.

molten yarrow
cinder patio
#

.replace is not an array method

eternal osprey
#

yeah sorry mistaken.

#

I can use splice for an array right?

cinder patio
#

yes

earnest phoenix
#

how to make separate files for separate functions in discord.js?

vague imp
#

Where you separate function

earnest phoenix
vague imp
#

Well then you already got it enjoy

earnest phoenix
vague imp
#

Make a command handler

#

Where you read files as command

earnest phoenix
#

Whats What I Can't Make

#

like how

#

look at 3rd line

vague imp
#

No

earnest phoenix
#

then

molten yarrow
#

google it... we dont give you whole code here :3

vague imp
earnest phoenix
#

im not even asking for full code

#

tf

#

you peeps dont know yourself

cinder patio
earnest phoenix
#

im not new

umbral zealot
#

so did you forget to add the word require or something?

#

maybe just not paying attention to the actual literal code you have? Thonk

cinder patio
#

You are obviously new if you don't know require

umbral zealot
earnest phoenix
#

still not helping

umbral zealot
#

How isn't it helping?

earnest phoenix
#

: (

umbral zealot
#

it explains everything you need to know

earnest phoenix
#

i changed it To require(./commands/commands.js)

umbral zealot
#

ok and ?

earnest phoenix
#

do i need to add token in the the file also

#

**like execpt main js file **

cinder patio
#

require accepts a string

#

So you need to put the path to the file in a string

earnest phoenix
#

Im using this as token

#

client.login(process.env.token);

molten yarrow
umbral zealot
#

it'll help for sure

eternal osprey
#
 var cleared =  allItems.splice(final, ' ')
                console.log(cleared)
                fs.appendFileSync("./cart.txt", cleared)```
#

it doesn't delete the finals from the file.

umbral zealot
#

those aren't spaces they're line returns.

#

¯_(ツ)_/¯

molten yarrow
#

.splice() require an index

#

array.splice(index, howmany, item1, ....., itemX)

umbral zealot
#

you probably need to split by line return in the first place, remove what you want, and then join it again

eternal osprey
#

Okay thanks girls for the help!

earnest phoenix
#

Is getting inside a bot's account illegal?

eternal osprey
#

i can't provide an index for the splice as I never know how many products there are in a cart

earnest phoenix
#

Is getting inside a bot's account illegal?

eternal osprey
#
allItems = fs.readFileSync("./cart.txt", "utf8").split("\n").map(x => x.split(/ +/))
console.log(allItems)
let filtered = allItems.filter(x => x[0] === message.author.id)
let final = filtered.map(x => x[1]).join("\n")  ``` It can range from 0 to 23 products
molten yarrow
eternal osprey
#

yeah

#

but i don't know how much items.

molten yarrow
#

get the index of it

#

.indexOf()

eternal osprey
#

for me it might be 3, for someone else it might be 7 that needs to be deleted.

molten yarrow
#
const fruits = ["Banana", "Orange", "Apple", "Mango"];
const a = fruits.indexOf("Apple");

returns 2

umbral zealot
earnest phoenix
umbral zealot
#

why are you using bold, it's not like we can't read you.

earnest phoenix
#

By Entiring Inside it

umbral zealot
#

I don't know what you mean by "entering inside of it"

earnest phoenix
#

I Get more Attension With Bold

umbral zealot
#

no

#

it just makes you look entitled and obnoxious

earnest phoenix
eternal osprey
#

uhh

umbral zealot
#

if you can't explain it in words, then there's no point in talking about it

eternal osprey
#

i think that he means selfbots

#

Those are indeed not allowed.

earnest phoenix
#

Uh What are "SelfBots?"

umbral zealot
#

you mean using a bot token in the client? no you can't do that

#

It's not possible.

earnest phoenix
#

Yes it Is

umbral zealot
#

no, it's not

earnest phoenix
#

Its Possible

umbral zealot
#

you cannot use a bot in the discord client

eternal osprey
eternal osprey
umbral zealot
#

You literally cannot.

eternal osprey
earnest phoenix
#

Join my serrver ill prove

eternal osprey
earnest phoenix
#

sure

umbral zealot
#

There is no way to actually use a bot's token to interact with the discord client, they blocked that "feature"

earnest phoenix
#

DM IF YOU THINK IM LYING

umbral zealot
#

don't really care

eternal osprey
umbral zealot
#

do you have any programming questions maybe