#development
1 messages · Page 1475 of 1
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
yes
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
neat thanks!
use the join method and then the length property
Aight
@gloomy python
It returns a map
I think
then it increases
I think
every time react
I THINK
cwickks thinks he thinks
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
Question
hey
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);
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:
Ok
@eternal osprey bro are you using a txt file for a database
as a base.
I always start with bases, later on going to migrate it to Atlas.
wdym
fs.readFileSync("./cart.txt").toString('utf-8'); === fs.readFileSync("./cart.txt", "utf8"); lol
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.
I didn't know there was a reaction limit 🤔
you're using it as a read only reference for later?
yeah.
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.
each line is supposed to be an entry?
then you need to split by newlines, not by space
and what would that do?
make an array of lines
@quartz kindle or we could just do string.replace(/\\r\\n/g, "\n"); if we dunno the OS
yes
yeah i see, it returns 1.
but i am trying to split the id from the actual product name.
yes, but that comes later
first you split by lines, so you have the entries correct
otherwise you get that mess
it btw contains an \n
how did you split?
@eternal osprey array.forEach(e => array[array.indexOf(e)] == { id: e.split(" ")[0], name: e.split(" ")[1] }); might work
or use regex in the split if you don't trust yourself: / +/
i would just do this fs.readFileSync(...).split("\r\n").map(x => x.split(/ +/))
||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
its gonna be the same if they upload the same text file
me?
I am not deploying it to my vps.
i am not going to use this bot.

it is just pure so i can learn from it, once again.
what
what
you're developing a bot that you're never gonna use?
yup.
i have another bot that i hosted.
let them learn lol
how to host the bot 😭
okay so i understand this part, and i can now call the different string by using text1[0] and text1[1] right
you can buy a vps for only like 8 dollars a month.
galaxygate
yo i am switching up lmao.
i use repl.it digitalocean or google is a good vps too
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
is 1gb ram enough tho?
hmm interesting.
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.
anyways, is this true what i stated here?
your ram is almost maxed out tho.
owh i didn't see that.
hey this site actually has good plans for what you get.
thanks bro! Switching everything right now.
wait i don't get this part boys.
would i basically call the different arrays using text1[0] and text1[1]
or..?
unknown message
either the message is already deleted, or your bot cant see it for some reason
channel history perm maybe
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))
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));
try passing timeout directly, without using ms
But the function doesn't work unfortunately.
because you don't really need it in the first place
yes
from the ms docs:
so you were actually just passing a string to setTimeout
which it doesn't accept
Yes, unfortunately, but do you know the problem for this?
I want it to save twice.
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
the function in setTimeout never executes
because of this <#development message>
you also don't save in setTimeout
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.
🙄 have you been ignoring everything i've been saying to you
Yes, I am reading.
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
True, what can I do instead for long period of time?
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
Like every January and such?
But that will give the premium user more time than usual.
Making it unfair.
w h a t
please
either you're skim reading or you're not understanding what i'm saying
or both
... I just take time to understand.
lets try pseudo code instead
hi ok so
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
I mean , if you wanna make your life miserable
Sure ! Go ahead
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
//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
this question makes absolutely zero sense
no it does not
creating an oauth2 app and implementing discord oauth2 are two entirely different things
ah what
and one is much harder
yea ok
oauth2 is not something tied to discord lol
but the thing is

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
so... do that?
use a web server
by just putting it lol
i mean like i just stacked the codes on top of each other
and then whichever is above gets executed
your bot is not the application itself
your webserver is not the application itself
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
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
json db.................
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
so in /login you wanna get the query (code)
ye
as discord redirects to /login?code=OAUTHCode
yep
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
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?
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
so i should remove the if
and use
because that is what we want to do
no you put the Array.some inside the if statement
aha oaky
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]
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
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])
}
}```
try text2.some then
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
You could try using a json file, you won't need to split in that and it'll be a lot simpler
a json file doesn't accept text.
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"]
hii guys i need help of a developer who uses java
a JSON file is like an object
i am not only in need of having the ids.
345138133429649408 2K2RKit
345138133429649408 AxuasKit
345138133429649408 FlyKit
anyone knows?
i am basically checking the id with the message.authoer.
or anyone can help me?
then i want its text behind the id.
what about
{
"345138133429649408": "2K2RKit",
"345138133429649408": "AxuasKit"
}
something like that
then you can do
[["345138133429649408", "2K2RKit"],
["345138133429649408", "AxuasKit"],
["345138133429649408", "FlyKit"]]
if (adminIds.some(id => message.author.id === id[0])) {/*code*/}
no one helping me
kek, don't ask to ask
@unkempt ocean no one helping or telling me here
what to do
BRO WHAT IS UPPP?

Smh
because you're only using the first one
yeah i understand that.
i need hel of a java developer or someone who knows java @eternal osprey
s o that's why i asked how to take them all
well I dont.
ask your question first, dont ask if someone knows first
nobody is gonna say "i know, what is the question"
everyone is waiting for what the question is
i need a code which brings bot online the one i watched on yt showing errors even i am typing the same
your text2 variable is using text1[0], aka only the first item
^^
sry
well, show the code
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();
}
}
hmm so i would have to use the text1[0] instead of the text2[0]
no, that has nothing to do with it
you are only using the first item, and then asking why its not finding the other items lol
but how would i get all the available items then?
just not gettin this error
Multiple markers at this line
- The value of the local variable builder is
not used
oo ty
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.
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
huh when
allItems = fs.readFileSync("./cart.txt", "utf8").split("\r\n").map(x => x.split(/ +/))
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
newlines are hella confusing
and i don't even know how much products it contains
sometimes they are \n and sometimes they are \r\n
how to create an immutable array in js/ts?
ok, how to let ts know about it?
so it wont suggest the push and pop method on that array
that looks like your newlines are using \n and not \r\n
did you save the file using code?
because if you save it using notepad, windows automatically adds \r\n
using code.
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
Nah! TS has given the array readonly type. So now it is not suggesting those methods 🙂
but @quartz kindle
the problem is, is that I don't know how much products it contains
just do .split(/\r\n|\r|\n/) to account for both lol
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
hmm okay
you might want to remove empty lines tho, it seems like your file has an empty line at the end
but how would i seperately call the first array, and the second?
.split(/\r\n|\r|\n/).filter(Boolean).map(...)
items[row number][column number]
items[2][1] = data of 3rd item, items[5][0] = id of 6th item
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.
how doesn't it matter if i don't know what to call?
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
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.
items.filter(item => item[0] === id)
And why are you storing all that in a plain text file and not a database? Even json would be better than plain text
that's just how i work.
i first start the base using text
then over to database.
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
hello my friends, is there anyone to help me?
yeah sorry you lost me there
My bot is approved but I was not on the server then what should I do?
what dont you understand?
do you not know about array.filter?
i know array.filter
but the problem here is.... i still don't understand the column shit etc.
[
[a1,b1,c1]
[a2,b2,c2]
[a3,b3,c3]
]
``` this is how your data looks like after splitting
yeah
allItems*
yes
okay yeah i got that
but i have 23 products, so how in hell am i gonna know how much products someone addst o
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]
]
array of arrays
items.filter(item => item[0] === 964958734589)
/*
[
[964958734589, someproduct]
[964958734589, someproduct2]
[964958734589, someproduct3]
]
*/
there’s just something funny about that
yes
and later on message.channel.send(allItems)
let filtered = allitems.filter()
ofc you have to define a variable to it
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")
and i should define another variable to this to later on send it right
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
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.
@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
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! 😆
that is still treated as a string
you cannot take a random string and treat it as code
could you replace it?
.replace('username', message.author.username)
use this ^ but don't forget to replace globally, otherwise it will replace only the first occurance
you can add placeholders
for example ```js
string = "ououg weughowuehwgh ou %%USERNAME%% ouhowuehowute"
string.replace("%%USERNAME%%", message.author.username)
Oh
french 😍
wat
i was kidding
.setDescription(permissions.test.replace("username", message,author.username))
lmao
Like that?
lmao
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
u know that tim?
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
What do you mean? Like should I put something like [] at the beginning and end of the word or what? Didn't understand.
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
Yes, so I can put some type of sign near the thing I want to replace, right?
yes
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");
});
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?
old, existed before bot started
you need to enable partials for that
already 🙁
show client options
var client = new Discord.Client({ partials: ['MESSAGE', 'CHANNEL', 'REACTION'] });
needs USER too
ty so much!
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
(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 >_>
probably means your bot is not logged in
do you use env or config.json?
make sure token is defined
token is directly on the main file
I don’t use either I use info.json
harcoded?
token unavailable also happens if you remove the token after the bot starts
for example client.token = null
oh
show your code
how many other files 
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
most people make an event handler for that
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
Tim do you know how I should cache mongoose?
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
why store in txt files
I read this but they were just setting data to a value, where I want to be able to find data using multiple queries
instead of memory
what
yeah cache it
wait you can do that
yes
is it server specific?
caching is not specific to anything except process
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
why did you use client.destroy?
all it does is kill the client
not very good for shutdown
Deb, make sure you're not running two instances of your bot
yea
i wanted to see if all my commands had their config property when requiring the file
and if one didn't then it will crash the bot
hmm
use process.exit()
whats the best way to clean text of anything that can't be in a url
URLEncoder if in java
In js idk, but there's probably some lib to encode to url
Maybe even vanilla
probably lemme check
what do you mean?
@crimson vapor it's blank my workspace disappeared
I opened
Lemme restart my computer
Maybe some other problem
BTW which language u use?
Ic may I take help from u when I need
I am new
And yes problem solved ty
💪😄👌
@crimson vapor tell me
ah yes
the hand arm
probably but idk much java
i have to rework my help command :/
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');
});
}
});
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
...reply to the email?
adding roles according to the reactions
remove user.id from this part
fetch needs to be empty
instead of get() use fetch()
fetch is a promise so you need to await it
and then you can do your .roles.add
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"];
jobchoices.includes(args[0])
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)*
there must be a space between else and if
its elif
yikes I prefer to use arrays and .includes rather than chaining if statements
and if requires brackets
no elif in js
oh
it requires brackets
o
Yep
// 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
the 4th one is just py
py is weird
eh i have a really messy job command
so basically, if they dont specify args it tells them what jobs they can choose
yes
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
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
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
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}`)
hm
ok
maybe ill just do toUpperCase
but then thatd make everything
uppercase
oof
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
o
ok
this is 1 hour in millseconds
right
1000 * 60 * 120;
and then 2 hours would be 1000 * 60 * 180 right
does anyone know any bots that can give everybody in the server one role
i think one hour in ms is 1 * 60 * 60 * 1000
o
dyno?
?role all +rolehere
180 is 3 hours
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
order of multiplying does not matter
im not printing the hours
are you leaving out the

yeah
bruh wrong math
meth
nah i thought it would be 180
because it wasnt printing hours
i had 120 at first
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
bro just use npm.im/moment
THESE FUCKING ADVERTISERS DESERVE TO DIE IN THE LAVA PIT ON POLUS
moment is bloat
Mira HQ's fall damage: Am i a joke to you
@stable eagle The "no oxygen" in space in skeld: Yes I am actually a joke
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
{
"authorData": "❌ You do not have an economy account, be sure to create one by performing the **`!register`** command.",
}
and whats the code
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
🤦♂️
devid is defined as my user ID,
how come ${devid.user} prints undefined
nvm i needed to fetch
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.
idk if this might be the problem but
instead of using the regex constructor
just use /your-regex/flags
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
wait let me give you an example
k
This will work: (random:1=10);. This shouldn't be detected: (random:1=10)
oh so the $ isn't needed?
nope
Ohh, ok let me try
ight
Nice 😀 it works! Thank you.
np
oh yea also this
just to keep the thing clean
Ok 👍
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 ()
Can you send me autorol commands? I'm on the phone but
There's no "autorole commands", you need to write it yourself
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
buy?
okay
when i delete the message by clicking the reaction, it gives the console this error.
(node:15508) UnhandledPromiseRejectionWarning: DiscordAPIError: Unknown Message
look at Intl.DateTimeFormat() for your case
you're not defining the msg
so it doesn't know which message to delete
(i think)
or there is no message
hm
no let msg = await message.channel.send(${message.author}, embed);
new Intl.DateTimeFormat('en-GB', { dateStyle: 'medium', timeStyle: 'medium' }).format(Date.now())
should return something like this: > "23 Dec 2020, 19:14:52"
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
change en-GB?
new Intl.DateTimeFormat('en-US', { dateStyle: 'medium', timeStyle: 'medium' }).format(Date.now())
> "Dec 23, 2020, 7:16:40 PM"
a
we got a spammer here
u can use timeZone
@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"
woah thats a ton of code
i dont think that'd be a smart thing to do in a stats cmd
then you have to use moment.js
RangeError: Invalid time zone specified: EST
is it called ET
idk
whats your timezone?
i mean add timeZone: 'America/New_York' if u from NY
how did you know ok
hey @polar flower I actually had a question pending but it didn't send it.
you dont need other packages... @earnest phoenix
ok it works tysm! <3
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
what is allItems
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?
is allItems a string?
pff no.
how u using .replace on it?
Obviously allItems is not a string, console.log it to see what it actually is.
it's an array ofc.
.replace is not an array method
yes
how to make separate files for separate functions in discord.js?
modules
It's not just discord.js it's javascript
Where you separate function
no one cares about that i need answer
Well then you already got it enjoy
i want to divided commands in different file i want to keep code for every commands in a different file
No
then
google it... we dont give you whole code here :3

im not new
so did you forget to add the word require or something?
maybe just not paying attention to the actual literal code you have? 
You are obviously new if you don't know require
One of these things is not like the others.
Here is a great tutorial on how to make and use modules in your code : https://js.evie.dev/modules
still not helping
How isn't it helping?
: (
it explains everything you need to know
i changed it To require(./commands/commands.js)
ok and ?
you need your token only on client.login()
Maybe just read this: https://anidiots.guide/first-bot/a-basic-command-handler
it'll help for sure
var cleared = allItems.splice(final, ' ')
console.log(cleared)
fs.appendFileSync("./cart.txt", cleared)```
it doesn't delete the finals from the file.
you probably need to split by line return in the first place, remove what you want, and then join it again
Okay thanks girls for the help!
Is getting inside a bot's account illegal?
but the problem is
i can't provide an index for the splice as I never know how many products there are in a cart
Is getting inside a bot's account illegal?
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
but u want to remove an item from the cart?
for me it might be 3, for someone else it might be 7 that needs to be deleted.
const fruits = ["Banana", "Orange", "Apple", "Mango"];
const a = fruits.indexOf("Apple");
returns 2
What do you mean by "inside a bot's account"
**Using a Bot **
why are you using bold, it's not like we can't read you.
By Entiring Inside it
I don't know what you mean by "entering inside of it"
I Get more Attension With Bold
Want Demo?
uhh
if you can't explain it in words, then there's no point in talking about it
Yes it Is
no, it's not
Its Possible
you cannot use a bot in the discord client
are you trying to say that you are in the bot's account?
prove.
You literally cannot.
I know.
Join my serrver ill prove
no.
sure
There is no way to actually use a bot's token to interact with the discord client, they blocked that "feature"
Yes
don't really care
why are you being so stupid?
do you have any programming questions maybe

