#development
1 messages ยท Page 1937 of 1
lemme look for a way to use chalk in cjs
bot file ofc
bruh
i shoulda just used c# or something to code my bots
so i dont have to have this much pain every update
good luck
.NET has an intense learning curve
i know but i have to learn it for collage so it would atleast be usefull
should i just remove chalk from my bot
C# is much less forgiving than js, but it's a great language imo
i know and thats one of the good things i think
cuz if i get an error i want it to crash so i can fix it
unlike in js where it just spams the console
try manually converting chalk to cjs
how do i do that?
its more stable
especially all that get this get that killing the reuse of your program
it does but eh
npx esbuild ./node_modules/chalk/source/index.js --platform=node --outfile=chalk.cjs
people with glasses can use it
get it, see sharp
thank god I'm going blind in my right eye ๐
lol
ok so i did this what now should it all work or do i need to change the import thing back to what it was?
ESM is a new module loader that was created to replace require. however due to how different it is, they are not easily compatible with each other, so to use ESM your entire project as to be ESM, otherwise the engine wont know how to load non ESM files
const chalk = require("./chalk.cjs");
console.log(chalk);
try this see what happens
there are many different ways to deal with this
one way is to downgrade the chalk version to the last version that was not ESM
i might do that if this doesnt work
another way is to use a dynamic async import, like this: chalk = await import("chalk")
or just not use chalk at all
why can't i use named exports in cjs?
literally just
module.exports = { name: () => {} };
import { name } from "cjs";
another way is to convert your entire project to ESM by setting "type": "module" in your package.json
i thryed that but i cant import discord then
another way is to not use chalk
discord.js cringe
and the error i got i googled and it just said to remove the "type" thing
you probably tried import { Client } from "discord.js";
named exports in cjs and in esm are two different things
cjs named exports are runtime, only when the code is run, are the names checked and used
esm named exports are statically typed during file analysis, before loading
meaning its more like typescript
it already knows what the file exports before actually running the file
to use import statements, your project has to be set to module in your package.json
the easiest fix is to use dynamic async imports
const chalk = await import("chalk")
oof forgot --bundle
npx esbuild ./node_modules/chalk/source/index.js --platform=node --bundle --outfile=chalk.cjs
ah
i just removed chalk from the bot but ill try to get it to work later cuz my other bots use chalk alot more
i know ima have alot more issues with getting my bot working after updating to v13
this is starting to feel like trading solana on an ethereum exchange
how do intents work? cuz thats a new thing now (well to me probably)
i looked on the internet abit and the people on stackoverflow just say to enable everything
but i dont really want to do that
You want to enable intents for events you want to receive basically
So if you want your bot to be notified when someone sends a message in a guild, you want the guild message intent
ah ok
But if you don't want your bot to be notified when say, a new channel gets created, then you don't need the channel update intent
You only want to ask for intents you need as it saves your bot ram and cpu and stuff 
my bot just saves a massage you send it so i will need the msg intent
isnt msg content a separite intent now too?
Message content intent will be privileged soon
yeah
Yeah guild message and message content is seperate
cool
But you will still received message content if your bot is pinged in the message
Or dmed it
yeah read about that cuz i might have to change the prefix for my bot to use mentions
Or slash commands, yep
They're going to get better from where they are now
true
Normal commands will be harder and harder to use until everyone's kinda forced too.
yeah
I use mention prefix for like, eval and owner commands but that's it
eh, some developers will choose the stubborn route regardless
Slash commands are pretty much what you gotta do at this point
i know just having a prefix for a bot is kinda messy but the way slash commands work is also abit wack too
i want to change to slash commands but they are just too restrictive for the functions of my bot
I wish slash commands were more dynamic, like allowing bots to dynamically add/require inputs
What does it do that slash commands can't?
Wait, why can't you dynamically have inputs? Optional fields and whatnot.
Especially with the command input thingy that got added
For my case, I have a /tag command and wanted to add variables the user can use. For example, ?user jumps over the moon! and the user can run it with /tag get moon ... where ... is the variable value.
There's no good static way to do that
its for saving notes and info so for example you do
== write hello world this is an example
and the bot saves everything after the prefix formatting and all
since there could be an arbitrary amount of variables
the solution would be to use a delimiter like ,, |, etc. but that's yucky
and its really hard to type out things that use code blocks and the likes in a slash command
me when i get ddosed by discord
Lines are an issue fair,
Could still use slash commands and require the user to dm the bot the values.
So you stay compliant with the goals of discord, while keeping usability.
I think multi-line support is coming soon
well that would be a step in the right direction
cuz then i would expect that it would work just like sending a normal msg
we'll have to see
so im reading the docs and it says
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
for other intents do i just add them like
const client = new Client({ intents: [Intents.FLAGS.GUILDS], [MESSAGE.CONTENT] });
or is that not how it works?
You'll need to do Intents.FLAGS.[flag] for every one
ooh ok
like
const client = new Client({ intents: [Intents.FLAGS.GUILDS], [Intents.FLAGS.MESSAGE.CONTENT] });
```?
Stupid java question, but if I have a folder full of classes (that extend a base class) and I want to make an instance of each one of them without having to do T variable = new T(); for every class, is there a way to do that?
Maybe with the reflection API
but with a static language like java? not so easy
I think @lyric mountain did something like this before
this will give a syntax error
intents is a single array, not multiple arrays
intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.MESSAGE.CONTENT]
yeah i descovered that
is setting the status in the client still a thing?
const bot = new Client({
presence: {
activity: {
type: "PLAYING",
name: "==help"
}
}
});
``` like this
cuz thats what i did in v12 to stop my status going away after 5 seconds
but i cant do that with the intents aswell aparently
why will it go away
cuz my internet is bad
if the hartbeat times out or something and the disconnects and then reconnects so if its set normally it just disapears
that's a problem with the entire bot going down not just the status
i know you can just do it on a settimout loop but thats too messy for my liking
i mean if it disconnects and then reconnects really fast so the bot never apreas offline
that should still work in v13 yes
but how would i integrate that with setting intents aswell
lol
the same way as with any other options?
{ option1: blah, option2: blah }
yeah im dumb i forgot the comma at the end of the intents line
const botIntents = new Intents();
botIntents.add(Intents.FLAGS.GUILDS, Intents.FLAGS.MESSAGE_CONTENT);
const bot = new Client({
intents: botIntents,
presence: {
activity: {
type: "PLAYING",
name: "==help"
}
}
});
``` i found you can just do this
but it just says
knowing me i just spelled somthing wrong
You're probably looking for GUILD_MESSAGES
You can see the whole list here https://discord.js.org/#/docs/main/stable/class/Intents?scrollTo=s-FLAGS
ah cool
I did what?
MESSAGE_CONTENT is not a thing yet
isn't it?
Not exactly creating classes
But I used reflection to load annotated commands without needing to specify each one
ye that
I was going to release a command manager lib but...too lazy ig
You can still find the repo under my profile, it should be pretty functional as it is
It's named UCH, used the same method I used for my own commands
scroll down
and you'll find this
Tf
no, it was announced, but not released yet
because discord.js is planning to release it as a breaking feature
like everything else
why does everything use java
only 3 billion devices do
there's probably life support machines written in java
imagine there's an exploit or buffer overflow
EXPLOITKOPTER EXPLOITKOPTER
did you know your mother is powered by apache log4j
Ye so you could do something like this
https://github.com/OtagamerZ/ShiroJBot/blob/master/src/main/java/com/kuuhaku/managers/CommandManager.java
i have so many questions
like the fact that you're talking to the mirror
i like this one
i like your mom
and to think java is only third place in the languages with most vulnerabilities
what are those two languages behind golang
That's UCH basically
kotlin is like typescript but for java i guess
scala idk
functional programming in kotlin is fun
Okay so I've got a weird Java issue, java public void addOrModifyValue(String key, int value) { if(this.getValue(key) == -1) { this.addValue(key, value); } else { int i = 0; String[] content = new String[512]; // If you make more than 512 lines, you need help. try { Scanner scan = new Scanner(this.file); while(scan.hasNextLine()) { content[i] = scan.nextLine(); ++i; } scan.close(); } catch(Exception e) { // File 100% exists by now, this will never be executed } i = 0; StringBuilder sb = new StringBuilder(); for(String s : content) { if (s.contains(key + ": ")) { content[i] = key + ": " + value + "\n"; } sb.append(content[i]); ++i; } try { FileWriter writer = new FileWriter(this.file, false); writer.write(sb.toString()); writer.close(); } catch(Exception e) { // Failed to write } } } I have this code for a basic K/V store (for config stuff, making a minecraft mod to learn some more java), and I keep getting a NullPointerException on the line if (s.contains(key + ": "))
Java is unreadable on mobile ic
lol
ig but that still doesn't change the problem
issue is you're using java
What is the current class?
this is an instance of a class I've made for managing basic config settings in txt files
it just occurred to me, is this a bug in my top.gg code? Seems to happen randomly like once a day...
Like a properties file?
It doesn't really have anything to do with the issue since I've verified that the file exists
Yeah basically, just as a .txt
Java has native support for that
I know but I'm doing this to learn
Kotlin is the smart kid who copies your homework but fixes the errors you made
If it's a key=value
and that's as far as it goes
It's a key: value
java is unreadable everywhere
Properties with different separator then
I'm assuming that it's not reading the lines correctly or smth
Lemme do some logging and I'll give you more details
Oh I'm an idiot
I forgot that initializing an array like that makes all the other entries null since they're strings
That would make a lot more sense since I'm using a foreach loop so it's going over the null entries
the most vulnerable programming languages by flaws per megabyte of code:
Classic ASP โ 1,686 flaws/MB (1,112 critical)
ColdFusion โ 262 flaws/MB (227 critical)
PHP โ 184 flaws/MB (47 critical)
Java โ 51 flaws/MB (5.2 critical)
.NET - 32 flaws/MB (9.7 critical)
C++ โ 26 flaws/MB (8.8 critical)
iOS โ 23 flaws/MB (0.9 critical)
Android โ 11 flaws/MB (0.4 critical)
JavaScript - 8 flaws/MB (0.09 critical)
Btw u can use Objects.equals() which is null safe
Or use reverse equals
(key + ": ").equals(s)
the android programming language
the dotnet programming language
so they're just looking at codebases
makes sense for Android beating iOS given low-level C/C++/Objective-C history
Taking a closer look at PHP:
86% of applications written in PHP contained at least one cross-site scripting (XSS) vulnerability.
56% of apps included SQLi (SQL injection), which is one of the dangerous and easy-to-exploit web application vulnerabilities.
67% of apps allowed for directory traversal.
61% of apps allowed for code injection.
58% of apps had problems with credentials management
73% of apps contained cryptographic issues.
50% allowed for information leakage.
idk dont remember that
lmao
mmm i dont think it works
the bot has no status
follow the docs
it doesnt say anything about setting it when the client is made
or am i blind
wait lemme try somthing
that page is already for that
it shows you what is accepted inside presence: {}
inside Client()
oh i see
but
ok
im pretty confused now
const bot = new Client({
intents: botIntents,
presence: {
activity: {
type: "PLAYING",
name: "==help"
}
}
});
``` i have this and it doesnt work
no errors nothing
however i cant see any other way of doing it since thats all you need
did you read the docs?
yeah
i looked at the status one
today firenado learned discord.js sucks
i descovered that a while back im just lazy and dont fancy recoding all my crap in another language
Documentation for Detritus Client
don't use the actual docs tho
yeah read that and thats why i was confused cuz theres an example thing there and the way you set that is very symilar to the way you set the other thing
well idk do i this crap seems to change on a daily basis and i havent updated anything in like a year
So I'm still not quite sure how to do this properly. I've got ```java
import net.minecraft.command.CommandBase;
import net.minecraft.command.ICommand;
import org.reflections.Reflections;
import java.util.ArrayList;
import java.util.Set;
public class Commands {
private final ArrayList<ICommand> commandList;
private final Reflections refl = new Reflections("dev.jwaffled.dragsimutils.Commands");
private final Set<Class<? extends CommandBase>> cmds = refl.getTypesAnnotatedWith(Commands.class);
public Commands() {
this.commandList = new ArrayList<ICommand>();
for(Class<? extends CommandBase> cmd : cmds) {
commandList.add(cmd);
}
}
public ArrayList<ICommand> getCommandList() {
return this.commandList;
}
}
``` which is certainly wrong. All the classes in this folder extend CommandBase, but I can't figure out how to call the getTypesAnnotatedWith() function correctly
i cant see anything about why it wouldnt be working
type is set as PLAYING
name is set as ==help
i see no reason why this code does not work
(Also the commandList.add(cmd) gets mad at me since the type isn't matching, but anything extending CommandBase should be ICommand)
if(id === 'yes')
ButtonInteraction.first()
return; {
ButtonInteraction.editReply({ embeds: [yesembed], components: [row2] })```
How come it doesn't update?
Y'all just love seeing me everyday ikik ๐คฃ
dude? i literally showed you?

i just did and it just said what i already know
its the same thing
what same thing?
the docs say these are the only options
and i have set my thing to playing
and that should work
are you not getting what im telling you? lmao
the problem is not what you have inside your activity
This is why I use a client.on('ready') for my status's ๐คฃ
activity does not exist in the docs
its activities
and its an array, not an object
ah well
why did they change it to activities though
Client({ presence: { activities: [{ your activity data here}] } })
They just did ๐คฃ
because discord supports multiple activies
my brain hurts
what at the same time?
yes, not sure if bots support them tho
Heyo big man Tim, can you check out my little questionnn above^?
I deleted all my files by accident last night, I woke up and they aren't here, now nothing is working. ๐คฃ
const filter = (interaction) => {
if(interaction.user.id === interaction.member.id) return true;
return interaction.reply({ content: "You can't use this button" })
}
const collector = interaction.channel.createMessageComponentCollector({
filter,
max: 1,
})
collector.on('end', (ButtonInteraction) => {
const id = ButtonInteraction.first().customId;
if(id === 'yes')
ButtonInteraction.first()
return; {
ButtonInteraction.editReply({ embeds: [yesembed], components: [row2] })
Aaand that's why u use git kids
how to set folder limit in ubuntu?!?!1
what is the problem?
It doesn't edit.
It says "this interaction failed"
I think that's right iirc I did something like that, but idk if I did the return; {} right
const { SlashCommandBuilder } = require('@discordjs/builders');
const { Permissions, Discord, MessageActionRow, MessageButton, MessageEmbed, MessageSelectMenu } = require('discord.js')
const db = require('quick.db')
module.exports = {
data: new SlashCommandBuilder()
.setName('allow')
.setDescription('Allow Bumps to be Sent to the #bumps Channel.!'),
async execute(interaction, message) {
if(!interaction.member.permissions.has(Permissions.FLAGS.ADMINISTRATOR)) return interaction.reply({content: `You may **not** use this Command.`, ephemeral:true})
const embed = new MessageEmbed()
.setAuthor(interaction.user.username, interaction.guild.iconURL())
.setDescription(`**Are You Sure**?\n> \`Allowing bumps will allow other servers to send their servers Advertisement Automatically to your Servers Incoming Chanenl. Note: These are w/o pings, so you can Mute the channel.\` `)
const yesembed = new MessageEmbed()
.setAuthor(interaction.user.username, interaction.guild.iconURL())
.setDescription(`**Bumps are now allowed to be sent in ${interaction.guild}.**`)
const noembed = new MessageEmbed()
.setAuthor(interaction.user.username, interaction.guild.iconURL())
.setDescription(`Interaction Cancelled`)
const row = new MessageActionRow().addComponents(
new MessageButton()
.setLabel("Yes")
.setEmoji('917576157472362496')
.setStyle('SUCCESS')
.setCustomId('yes'),
new MessageButton()
.setLabel('No')
.setEmoji('917577322696171550')
.setStyle('DANGER')
.setCustomId('no'));
const row2 = new MessageActionRow().addComponents(
new MessageButton()
.setLabel("Yes")
.setEmoji('917576157472362496')
.setStyle('SUCCESS')
.setDisabled(true)
.setCustomId('yes2'),
new MessageButton()
.setLabel('No')
.setEmoji('917577322696171550')
.setStyle('DANGER')
.setDisabled(true)
.setCustomId('no2'));
interaction.reply({ embeds: [embed], components: [row] })
const filter = (interaction) => {
if(interaction.user.id === interaction.member.id) return true;
return interaction.reply({ content: "You can't use this button" })
}
const collector = interaction.channel.createMessageComponentCollector({
filter,
max: 1,
})
collector.on('end', (ButtonInteraction) => {
const id = ButtonInteraction.first().customId;
if(id === 'yes')
ButtonInteraction.first()
return; {
ButtonInteraction.editReply({ embeds: [yesembed], components: [row2] })
}})}}```
that return makes no sense
lmfao, yeah ik
are you kidding me all i had to do was d and "ies" and [] to fix this the whole time
AAAAAAGH
I figured.
anyway thx for the help guys
thats what i was showing you this whole time
Do you guys think regex would be faster than using a for loop on a string? I want to write something like a markdown parser and I'm not sure If I should just use a for loop or regex, all the major markdown parsers are using regex
how can I put a return that actually works?
Regex is never faster
๐คฃ
now my bots working on d.jsv13 so that cool
regex is some parser
i know that now lol
regex will be faster than a loop, if your loop is gonna iterate over all characters
I see, well yeah it's gonna iterate through all of them
fuck reflection
but the thing is that multiple different regexes will be ran on the same string a lot of times
i have no idea what you're trying to do with this
let clientPerms = [];
command.ClientPerms.forEach((perm) => {
if(!client.member.permissions.has(Discord.Permissions.perm))
{
clientPerms.push(perm);
}
});
ClientPerms: ["BAN_MEMBERS"],
RangeError [BITFIELD_INVALID]: Invalid bitfield flag or number: undefined.
Yeah, I just did if(id === 'yes') { and it worked ๐คฃ
but I am trying to get it to edit to a embed, but I just fixed it. Now I just need to figure out how it can edit a embed upon click ๐คฃ
Nah reflection is a godsend when you understand how it works
if you're worried about performance, the fastest way i can think of is using a loop/recursion in combination with string.indexOf and/or an index based regex
string.indexOf is stupid fast
aaaand there's my problem!
What are u struggling?
I'm trying to make a command handler for some minecraft commands with reflection to get each command class, and I just don't know what to do
I've got this atm: ```java
package dev.jwaffled.dragsimutils.Commands;
import net.minecraft.command.CommandBase;
import net.minecraft.command.ICommand;
import org.reflections.Reflections;
import java.util.ArrayList;
import java.util.Set;
public class Commands {
private final ArrayList<ICommand> commandList;
private final Reflections refl = new Reflections("dev.jwaffled.dragsimutils.Commands");
private final Set<Class<? extends CommandBase>> cmds = refl.getTypesAnnotatedWith(Commands.class);
public Commands() {
this.commandList = new ArrayList<ICommand>();
for(Class<? extends CommandBase> cmd : cmds) {
commandList.add(cmd);
}
}
public ArrayList<ICommand> getCommandList() {
return this.commandList;
}
}
where do you define command.ClientParams?
while saving slash commands
But the problem is that commandList.add(cmd) doesn't accept it because it has to be of type ICommand, but anything that extends CommandBase should be ICommand
i mean, show what command.ClientParams is
(And I've got this problem with creating the set of commands: Cannot resolve method 'getTypesAnnotatedWith(java.lang.Class<dev.jwaffled.dragsimutils.Commands.Commands>)')
let MemberPerms = file.MemberPerms || [];
let ClientPerms = file.ClientPerms || [];
const data = { name, description, options, MemberPerms, ClientPerms };
and then you do command.ClientPerms = ClientPerms?
Yes
module.exports = {
name: 'user',
description: 'Get some info about Discord User',
options: [{
name: 'target',
type: 'USER',
description: 'Select a user',
required: false,
}],
MemberPerms: ["BAN_MEMBERS"],
ClientPerms: [],
async run(client, i, lang, options) {
I know this is wrong needed perm just did for try
what is this supposed to be?
although seems everything works except for adding the command to the ArrayList when I do ```java
public class Commands {
private final ArrayList<ICommand> commandList;
private final Reflections refl = new Reflections("dev.jwaffled.dragsimutils.Commands");
private final Set<Class<? extends CommandBase>> cmds = refl.getSubTypesOf(CommandBase.class);
public Commands() {
this.commandList = new ArrayList<ICommand>();
for(Class<? extends CommandBase> cmd : cmds) {
commandList.add(cmd);
}
}
Discord.Permissions.BAN_MEMBERS
well thats not BAN_MEMBERS, that literally perm
if you want the value of perm you need to use []
Discord.Permissions[perm]
otherwise its literally perm
Same error if you mean
Discord.Permissions[perm]
show code
async member({member, command})
{
let memberPerms = [];
command.MemberPerms.forEach((perm) => {
console.log(perm)
if(!member.permissions.has(Discord.Permissions[perm]))
{
memberPerms.push(perm);
console.log(perm)
}
});
if(memberPerms.length > 0)
{
return `Looks like You're missing the following permissions:\n${clientPerms.map((p) => `\`${p}\``).join(", ")} `
}
}
const MP = permChecker.member({
member: int.member,
command: command
})
and export
i get BAN_MEMBERS when i log perm
show full error
Unhandled Rejection at: Promise {
<rejected> RangeError [BITFIELD_INVALID]: Invalid bitfield flag or number: undefined.
at Function.resolve (C:\Users\aydin\Desktop\absda-main\node_modules\discord.js\src\util\BitField.js:152:11)
at Permissions.has (C:\Users\aydin\Desktop\absda-main\node_modules\discord.js\src\util\BitField.js:44:28)
at Permissions.has (C:\Users\aydin\Desktop\absda-main\node_modules\discord.js\src\util\Permissions.js:54:85)
at C:\Users\aydin\Desktop\absda-main\util\PermChecker.js:29:36
at Array.forEach (<anonymous>)
at PermChecker.member (C:\Users\aydin\Desktop\absda-main\util\PermChecker.js:27:29)
at Object.execute (C:\Users\aydin\Desktop\absda-main\events\interaction.js:25:30)
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
[Symbol(code)]: 'BITFIELD_INVALID'
}
}
PermChecker.js:29 is that code?
Yes
console.log(perm || "undefined")
BAN_MEMBERS
Result
BAN_MEMBERS then the error?
then when does the error happen?
When someone doesnt have BAN_MEMBER perm and tried to run code
did you test it after changing .perm to [perm]?
Yes
With perm and with no perm
then why are you not testing now?
Testing what?
I tried it
Bitfield is invalid
...
you said there is no error in the logs
im asking you to test WITH the error
i want to see where the error happens
in the logs
and what is logged right before it
Okay
I tested with perms = no error
I tested without perms = bitfield is invalid
show logs
i console logged perm and get BAN_MEMBERS result
show logs with the error
thank you
Dont take care Promise { undefined }
are you using v12 or v13?
13
v13 is Discord.Permissions.FLAGS[]
Hi! Is there a more concise way of writing emojis because I'm hitting the character limit in the embed (I'm constructing a game board with emojis). Even saving one character would save me
\<a\:_:012345678901234567>
ok, ignore backslashes but it's what I use
Are you using embed descriptions for the content?
I'm using a field
That's why
A field is only 1024 characters but description supports up to 4096 characters
oh ok I'll try that, thanks!
Back again
TypeError: Cannot read properties of undefined (reading 'guilds')
${client.guilds.cache.size}```
*Istg if this is a easy fix, which ik it is *
const client = new Client({
// partials: ['MESSAGE', 'CHANNEL', 'REACTION' ],
allowedMentions: { parse: ["users", "roles"] },
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
// Intents.FLAGS.GUILD_MEMBERS,
//Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
// Intents.FLAGS.GUILD_WEBHOOKS,
// Intents.FLAGS.GUILD_INVITES,
// Intents.FLAGS.GUILD_PRESENCES,
],
});```
That's client
In my main file.
Where did you put this line of code?
Y don't u just use annotations?
async execute(interaction, message, client) {
Add console.log(client) in the next line
undefined
Then client is undefined
I've never done reflection, not sure what that even is
@ACommand
Then get all classes annotated by that
wym?
I spent 3 hours debugging a network problem caused by listening on 127.0.0.1 instead of 0.0.0.0 I'm gonna go stop programming forever now bye
rip
I would just do class @CommandName then?
Nono
you need to show more code. you are using client in a place where it doesnt exist
@Command
public class Somewhat {
for starters, show the full error so we can see where is this client not existing
With annotations you can also pass pre-defined values like name, category, misc shit, etc
sounds more like networking
show setchannel.js
const { SlashCommandBuilder } = require('@discordjs/builders');
const { Permissions, Discord, MessageActionRow, MessageButton, MessageEmbed, MessageSelectMenu } = require('discord.js')
const db = require('quick.db')
module.exports = {
data: new SlashCommandBuilder()
.setName('channel')
.setDescription('Yep Yep!')
async execute(interaction, message, client) {
if(!interaction.member.permissions.has(Permissions.FLAGS.ADMINISTRATOR)) return interaction.reply({content: `You may **not** use this Command.`, ephemeral:true})
interaction.reply({ content: `Server count: ${client.guilds.size}.` })```
Skill issue 
literally is a skill issue cuz I didn't know about internal/external networks
now show index.js line 68
await command.execute(interaction);
thats your problem
hm?
you dont give it a message nor a client
that makes life a hell of a lot easier, thank you so much @lyric mountain
where is message and client supposed to come from?
Ah got it
async execute(whatever you write here only exists if you give it to the function when you use it)
For sure it does
command.execute(write here whatever you want to exist inside the function, in order)
await command.execute(interaction, client);
interation, message, client?
but in the file you have interaction, message, client
client is the 3rd one, not the second one
or remove message altogether
there is no message in interaction events anyway, so its useless to have it there
Only problem is that when I do getTypesAnnotatedWith(Command.class) it returns Class<?> when it needs to return Class<? extends CommandBase>, is there a simple fix for that that you know of?
Anyone know how I can verify that a message link is a valid link? Trying to move from message ID's to be more user friendly.
You could verify each one (HTTP request), but I'd rather just leave it in whatever store and run the validation when it's read
you can extract the channel/message id from it
and then do a fetch to the dapi/cache
Cast
Ah I guess that makes sense.
Get constructor -> new instance
It'll build into an object, which can be cast to whatever u extended it to
Big success?
public Commands() {
this.commandList = new ArrayList<ICommand>();
for(Class<?> cmd : commands) {
try {
commandList.add((CommandBase) cmd.getConstructor().newInstance());
} catch(Exception e) {
// Nothing
}
}
}
``` this doesn't produce any compilation errors
but it doesn't work
Does ur constructor have args?
Nope
I tried logging the error in the catch but nothing was produced
But there is a crash log
// I bet Cylons wouldn't have this problem.
Time: 12/12/21 1:22 PM
Description: There was a severe problem during mod loading that has caused the game to fail
net.minecraftforge.fml.common.LoaderException: com.google.common.util.concurrent.ExecutionError: java.lang.NoClassDefFoundError: javassist/bytecode/ClassFile
at net.minecraftforge.fml.common.LoadController.transition(LoadController.java:162)
at net.minecraftforge.fml.common.Loader.initializeMods(Loader.java:739)
at net.minecraftforge.fml.client.FMLClientHandler.finishMinecraftLoading(FMLClientHandler.java:310)
at net.minecraft.client.Minecraft.startGame(Minecraft.java:538)
at net.minecraft.client.Minecraft.run(Minecraft.java:364)
at net.minecraft.client.main.Main.main(Main.java:116)
... more garbage below
Minecraft Crash Report
Do you have a public constructor for that cmd?

all of the constructors are public yes
Not entirely sure how to do that, I don't think that's the issue though
If it helps this is my annotation: ```java
public @interface Command {
}
Does it have to not be empty?
No I meant that's how I'm declaring my annotation
@Command
public class HelpCommand extends CommandBase {
public HelpCommand() {
}
I see what u mean
That's how I'm using it
private final Reflections refl = new Reflections("dev.jwaffled.dragsimutils.Commands");
private final Set<Class<?>> commands = refl.getTypesAnnotatedWith(Command.class);
There I retrieve and build the command
Doing it essentially the same way you're doing it
Hey there, so how would I make it so like
/setupdates #channel
Get's saved to the quick.db db
Then when I run
/publish [update]
It finds each channel that was saved into the DB, and sends it to that channel?
U forgor retention
I didn't even know I had to do that lol
Annots aren't present during runtime by default
Target defines what will be annotated
oh ok
Type means only classes will be
It helps performance too since it'll be less guessing for the runtime
Crashes once again with the same error
Even with retention
I really think it's something to do with this line commandList.add((CommandBase) (cmd.getConstructor().newInstance()));
o-o
Actually wait
It's crashing before it even gets to that line
Since nothing logs
It's saying line 12 which is ```java
private final Reflections refl = new Reflections("dev.jwaffled.dragsimutils.Commands");
Wait maybe it's a circular dependency issue or something since I have the CommandLoader class in the same directory as the commands
I'll move it rq
Nope
damn it java why can't you be simple D:
I have a ping command, and I want to add a button that reloads the ping, what should I be exactly calculating in that button?
Just re-put in the ping code tbh
Uhh, that's not how it works? (ItsNoah)
one sec.
technically, it is
let before = new Date().getTime()
do some api operation
let ping = new Date().getTime() - old
put the annotation somewhere else
probably not the issue, but it might cause some circular issues
Yeah*^*, since you are updating the embed, it sends a new description with the updated ping.
At least from what I know
Alright, did that
I still didn't understand.
also, refrain from having titlecased folders
when you update the embed it'll take some time since it's an api operation
Yeah I'm used to naming conventions for C# and stuff so that's why it's title cased
that time is the ping
I'll change it in a little bit though
are u using intellij?
Yup
Indeed, how can I get the time from when it starts to edit to when it finishes. This? How so..
record the time before
on update, do the calc
.setDescription('My ping is ${new Date().getTime() - old}ms')
old as in.. OHH I got you.
the time before you update
what is the exact error?
like, run the code directly
This sounds like a lot of work for convenience.
to check if it isn't some forge limitation
welp this might be a forge limitation
it pays for itself in the long run
nhe
KuuHaKu, can you help me rq?
with?
Hey there, so how would I make it so like
/setupdates #channel
Get's saved to the quick.db db
Then when I run
/publish [update]
It finds each channel that was saved into the DB, and sends it to that channel?
That ๐คฃ
But the long run is not needing to add an element to a list
agh this looks sucky
also easier maintenance, better data visualization and less ram usage (since you aren't instantiating a biggus list)
I'm pretty positive q.db supports array's so would I just add all the channels to a array?
reflection is fun since you can write a lot of metaprogramming
I'm mostly doing this because it's an interesting problem to solve
And it'll pay off when I don't have to write new TCommand() every time I want to add a new command
better data visualization
[citation needed]
and less ram usage (since you aren't instantiating a biggus list)
but you're still keeping it in memory. unless you're recomputing the commands list every time (worried)
also I can filter by annots without even initializing the class
but you're still keeping it in memory. unless you're recomputing the commands list every time (worried)
you'd be using the classes which are already loaded by the classloader
instead of having dual reference
Looking at the forge ReflectionHelper class I don't think I'm going to be able to do what I want to do
lul
[citation needed]
my image above
you can have huge amount of data describing a class without going for static fields or having to construct the object to read
also annots allow optional fields (and default values), which is nice
tbh default values was what made my eyes shine
damn that shit is useful
you received 500
not something you can fix on your side
unless the api is shitty and didn't properly check inputs
nice webhook url btw (delete that or get it spammed by someone)
mb thx
I meant the webhook actually, not the image
but anyway
check if you're passing all the required arguments
and that they're within expected types
So why does this not add to the array, rather than replacing it?
db.push(`bchannels`, [channel.id])
never used quick.db
I've never used array's in quick.db before ๐คฃ
usually in sql you'd not have arrays at all
iirc quick.db sucks with arrays
they'd be either serialized data (like json arrays) or secondary tables
its been like 3 years since i used quick.db tho
I'm sure it does
try asking in their support server?
iirc quick.db sucks with arrays
I imagine using raw sql would be easier and probably more optimized
quick db stores data in key-json pairs
which idk how it could be a good idea
just got told in the forge discord "we're not going to support reflections for the purpose of being lazy"
๐
I mean, they also have a shitton of boilerplate code and unoptimized shit
like reloading ALL resources (I mean ALL) during startup or when you change packs
guess why fabric exists?
I wish they did accept outside opinions and reworked their codebase, much of the old code still exist for absolutely no reason
oooo cm advertising ban ban
forge is pretty terrible
it's against their rules in their discord to ask questions about any versions before 1.16
I stopped using forge recently
now i use fabric
the only redeeming qualities of forge is the amount of mods and the cross-mod compatibility stuff
like FE and fluids
other than that, fabric would easily win against it
they have a large userbase from when it became popular as one of the only modding tools out there
ye
that's the only reason it wins against fabric and other stuff
the issue is that for most (including me) they are chained to forge due to their mod catalogue
let channels = db.fetch(`channels`)
let ch = client.channels.cache.get(channels)
ch.send({ content: `Testing` })```
The let channels are in a array.
you cant do that
wym?
no
you have to loop over your array, and do something with each id
thats what loops are for
for(let item of array) { do something with item }
Wait how would I just get 1 of the ID's then?
I don't think I can.
Oh, i misunderstood the question 
confusion
what dont you understand?
if you had this array: let array = [1,2,3,4,5]
and you did this for(let item of array) { console.log(item) }
you would get in your logs: 1 2 3 4 5
So I litearlly put
each item would be separately logged
{}```
What do I put for the variable and array tho?
<variable> is the name you want each item of the array to have
<array> is the array holding all your items
have you ever used .forEach()?
.....
Do I define channel before for(channel) or what?
This is making literally no sense
please read this
The for...of statement creates a loop iterating over iterable
objects, including: built-in String, Array, array-like
objects (e.g., arguments
orย NodeList), TypedArray, Map,
Set, and user-defined iterables. It invokes a custom iteration hook with
statements to be executed for the value of each distinct property of the object.
Ah
Okay.
That cleared things up
let channels = db.fetch(`channels`)
for (const element of channels) {
channels.send({ content:`Testing` })
}```
Correct?
nope
That's literally what the thing is telling me to do!!!
no its not
first of all, the example in the link above is doing console.log(element) not console.log(array1)
mhm?
So I need to send the stuff to the array 
lmfao, so confused.
look at the example
I dfid
const array1 = ['a', 'b', 'c'];
for (const element of array1) {
console.log(element);
}
// expected output: "a"
// expected output: "b"
// expected output: "c"
you see console.log(element)?
dude seriously
why do you think that is?
exactly
Tim, god bless you you just made that make so much sense ๐คฃ
bruh
let channels = db.fetch(`channels`) for (const element of channels) { element.send({ content:`Testing` }) }
Element
Woooo
Oh jeez
because your code is assuming that each element is a discord.js Channel object
which probably isnt
so first console.log(channels) to check what they actually contain
(before the for line)
alright, so its an array of ids
2 of em hmm 
so first, you need to use the id to get a discord.js Channel object
you already know how to do that
hint: ...get()
foncusion
Oh nvm
Okay, you explain it out step by step, and I will write what I think makes sense, then you can tell me if I followed along or not.
```let channels = db.fetch(channels)
for (const element of channels) {
let ch2 = client.channels.cache.get(element)
}```
Sum like that?
yup
Wooo!
So then that moved it to a seperate channel ID of its own
So then I can run ch2.send
Right?
Hey tim how would I get the content between two characters using indexOf
considering they could be nested, for example:
{}
}
I can't think of a way to do it without looping through every character
May have taken me a second to understand, thanks for being patient with me tho lol
you can try running another indexOf from that point on and search for another opening bracket, then when you find none, you begin finding the closing ones
or you can use regex to search for one of opening or closing
there is a way to use regex with indexes
so you can properly navigate through substrings
Actually I think looping here wouldn't be bad because I'm going to loop only through a part of the string
from the start of the character to the end
While using regex I'd have to test against the entire string or create a copy
Okay now what did I do
deferUpdate?
let channels = db.fetch(`channels`)
for (const element of channels) {
let ch2 = client.channels.cache.get(element)
await interaction.reply({content: `Bump Sent to all Receiving Channels.`})
await ch2.send({ content: `Testing` })
}```
not necessarily
const regExp = new RegExp(source, flags);
regExp.lastIndex = index;
let result = regExp.exec(string);
regExp.lastIndex = result.index;
thats essentially the regex way of defining a starting index like indexOf supports
all the code inside the for loop will get executed once for every element in the array
so if you have two channel ids, you send 2 messages, and you reply to the same interaction twice
so dont reply to the interaction in there
do it outside of the loop
I see
should i fix my rate limiting?
it's going to be hard to do
this wont work when it scales to multiple lambdas
you will need to track it in your db
which one do i need in the CAP theory?
consistency right?
i want to make sure two people cant join in the same slot
the db needs locks
i think
yes, consistency first, then if you have a central db availability would be second
is the db partitioned/horizontally scaled?
it'll be central db.
yeah horizontally scaled. they are all smol lambdas
hopefully dynamodb is consistent
but if the db itself is central and automatically scaled, then it should take care of consistency by itself
Amazon DynamoDB lets you specify the desired consistency characteristics for each read request within an application. You can specify whether a read is eventually consistent or strongly consistent.
A strongly consistent read in Amazon DynamoDB returns a result that reflects all writes that received a successful response prior to the read. To get a strongly consistent read result, you can specify optional parameters in a request. It takes more resources to process a strongly consistent read than an eventually consistent read. For more information about read consistency, see Data Read and Consistency Considerations.
noice
Apache HBase reads and writes are strongly consistent. This means that all reads and writes to a single row in Apache HBase are atomic. Each concurrent reader and writer can make safe assumptions about the state of a row. Multi-versioning and time stamping in Apache HBase contribute to its strongly consistent model.
DynamoDB uses eventually consistent reads, unless you specify otherwise. Read operations (such as GetItem, Query, and Scan) provide a ConsistentRead parameter. If you set this parameter to true, DynamoDB uses strongly consistent reads during the operation.
A strongly consistent read might not be available if there is a network delay or outage. In this case, DynamoDB may return a server error (HTTP 500).
Strongly consistent reads may have higher latency than eventually consistent reads.
Strongly consistent reads are not supported on global secondary indexes.
Strongly consistent reads use more throughput capacity than eventually consistent reads. For details, see Read/Write Capacity Mode
im too lazy to setup Apache HBase
Strongly consistent reads are not supported on global secondary indexes
oof
right in the gut
basically, just add ConsistentRead:true to your requests, and you're fine
actually that will work
i dont need my queries to be consistent, just my get calls
noice
How can I delete a global command again?
Use the delete endpoint https://discord.com/developers/docs/interactions/application-commands#delete-global-application-command
Integrate your service with Discord โ whether it's a bot or a game or whatever your wildest imagination can come up with.
How do I get the command ID?
you can fetch all commands, then search for it by name
If only it was that simple 
it is pretty simple
how come my bot can respond with slash commands in channels it cant even see ?
especially if you set the global commands on startup
since discord will return all the commands on that APi call
so you could store it in some value
because it doesnt need to see them
let commands222 = client.api.applications(client.user.id).commands.get()
console.log(commands222)```?
slash commands dont even need a bot in the server
it also doesnt seem to need a permission?
Just says Promise : <pending>
tf what?
for example: https://i.woo.pics/1d970eff10.mp4
promises need to be awaited
also you dont need that
you can use client.application.commands.fetch()
so then how do i actually restrict my bot to only reply in channels its actually allowed to? lol
but does it even work?
^
hax
botghost got a new meaning
check what channel the interaction came from
and reject it
yea im just gonna check bot permissions in the channel and then do nothing if not enabled
thats crazy though, im gonna have to try that out ๐
await console.log(client.application.commands.fetch())
Just says Promise Pending
do the await in the console.log
you need to await the fetch lol
not the console.log
console.log(await client.application.commands.fetch())
is discord gonna change the bot being able to reply to commands without being in the server thing?
no
feels like that could reduce ram a huge amount for the bot if it doesnt actually have to be in 500+ servers ๐
thats intentional
interesting
imo, there's a future which its standard.
finally people start getting it
it looks way cleaner, no more worrying about the fact you have 6 bots to get all the features you need
about time people start realizing they dont need the websocket at all
yea the slash commands is a huge step in the right direction to standardizing bots a bit more imo
although you'd sacrifice any and every feature that require seeing the server
like xp
^untrue
howso?
trigger your exp gain upon interaction
cursed
lol
kuuhaku do you know a good way to register subcommands in forge, or should I just do one massive switch case for all my commands
and pass off their args and such to different functions
still can have one xp bot I guess
like?
what do you mean by "subcommands"?
like using /dsu subcommand args
doesn't minecraft already support that out of the box?
Personally I'm worried that as soon as a bot need some data that's only available to websockets, they'll need to inherit all the stuff they worked towards avoiding
Do they?
like /time set day
Yeah but I don't know how to do that with my custom commands
Forge docs have been scraped off the internet I swear
you will need to plan your app ahead of time
I guess they are like discord slashes
yeah but requirements change
so you can decide correctly whether to go for websocket or not
most commands have type checking
I'm once again asking for multiple slash signatures
im fine with giving up on stuff like server count
tim am i right in recalling you had some lightweight discord js library going on a year or two ago?
yeah
still going?
pls remember the difference between <>, {}, [], (), and <arg:User>!!!
yeah, discord.js-light is up to date with discord.js v13
but there wont be a version for v14
๐ฎ how come?
im moving out of discord.js
sadness, what you moving to?
type, scope, index access, parens and mention
what do you mean exactly?
make timscript
any idea when v14 will be a thing?
lel
timscript sounds great
no idea
probably still a long way ahead
please tell me thats an actual thing, and if so, i need a link ๐
toml is, the meaning could be slightly off
lmao
๐
show code
The one amazing line of code:
I swear, if you say its wrong 
client.api.application.commands.delete('842493762621538364')
When I removed api it worked

๐
mood
my coding language: computer delete command 'id here'
and that doesnt work? ๐
** S I M P L E - W O R D S**
you said it worked once?
Ikr, that's what im sayingg!!
well it should work only once, since now its deleted
you can just remove the bot from the server to remove its commands i think?
but the command is still there.
or does it do that hour thing?
No, not global commands
Global commands load instantly when you add it.