#development
1 messages · Page 1908 of 1
if the command started with prefix or not
is that not what i did here
so you should check the messge.content.startsWith for '<@${your_bot's_id}>' then it'll always work no matter the username
Yea like fake said
Which will also work, yes
But the client user tag will always work, too as the bot is in the guild in the moment receiving the event
Doesn’t actually matter what you use
client.user.id works as well
okay
I always get confused between the mentions like @compact flume and @compact flume
Gimme a sec to clarify it
take your time
if (!message.content.startsWith(`<@!${client.user.id}>`) || !message.content.startsWith(PREFIX)) return
That link is very useful 👍
I tried this but the mention thing still isn't working
I tried both
with ! and without it
I''ll test it too
sorry my mistake
if you check if they are not true you should use &&
like this if (!message.content.startsWith(`<@!${client.user.id}>`) && !message.content.startsWith(PREFIX)) return
Now it will return if those both are false
shouldn't we use the or operator
No
Yea if you check if they are true
oh alright
Not or not is logical nonsense
I like to do it like that so the code wont be full of recursive ifs :D
isn't && the AND operator
yes
I still don't get this
so if those both are false, return
if the message doesnt start with mention AND it doesnt start with prefix, return
Nice!
Think in boolean lol
think in binary ;)
if( FALSE and FALSE ) error
false or false will always error
If both conditions aren’t false
In your case both prefixes can’t be used at the same thing
what do you have
client.on("messageCreate", (message) => {
if(!message.content.startsWith(PREFIX)) return;
if(message.cleanContent.startsWith(`<@${CLIENT_ID}>`) && message.cleanContent.startsWith(PREFIX)) return;
const args=message.cleanContent.slice(PREFIX.length).trim().split(/ +/);
const command=args.shift().toLowerCase();
if(!client.commands.has(command)) return "CommandNotFoundError";
try {
client.commands.get(command).execute(client, message, args)
} catch (error) {
message.reply(`There was an error executing that command.`)
}
});
yep
<@! is used when a member has a nick
alright
Dude
and you can remove if(!message.content.startsWith(PREFIX)) return;
Your prefix check on top
please copy this line to your code```if (!message.content.startsWith(<@!${client.user.id}>) && !message.content.startsWith(PREFIX)) return````
its the bots user id
alright
I know what is but why did you define a var?
you get the id from client.user.id you dont need to do your own CLIENT_ID
but that line works
still the same
client.on("messageCreate", (message) => {
if (!message.content.startsWith(`<@!${client.user.id}>`) && !message.content.startsWith(PREFIX)) return
const args=message.cleanContent.slice(PREFIX.length).trim().split(/ +/);
const command=args.shift().toLowerCase();
if(!client.commands.has(command)) return "CommandNotFoundError";
try {
client.commands.get(command).execute(client, message, args)
} catch (error) {
message.reply(`There was an error executing that command.`)
}
});
here s the code
dose anyone know how i can store data inside an array with mongo db?
Hmm, it works on my end..
Keep that in mind
Check for both
As one format is for members with and other without nicknames
Yeah was mentioned in the docs I sent
User or User (nickname)
Oh sry
Yee don’t worry
But the code will now think the bot's username is the command, the parsing has to be changed
Or the parsing has to be different when the bot is mentioned I mean
still not working
dose anyone know how i can store data inside an array with mongo db?
Try to use the client.user.tag instead of the ID
What do you mean it is not working?
Even if that’s nonsense but try it 
thats what i did
still not working
Just show code once more, please
well this is working on my end: ```
if (
!message.content.startsWith(<@!${client.user.id}>) &&
!message.content.startsWith(<@${client.user.id}>) &&
!message.content.startsWith(PREFIX)
)
return;
But that has to be changed later...
if (!message.content.startsWith(`${client.user.tag}`) && !message.content.startsWith(PREFIX) && !message.content.startsWith(`<@${client.user.id}>`)) return```
my if statement
it is wrong
You’re missing the message format
the first should read: !message.content.startsWith(`<@!${client.user.id}>`)
At least if that didn’t work we now know his bot has a nickname
It will work
That’s the reason the original check with user only didn’t work
True
The one he wrote
im dying
i tried printing in the console what .cleanContent prints and it only prints User Name and tried checking for it but it still doesnt work
I don’t see any use case for that property other than logging stuff
Or cross posts without mentions
i dont know what you mean
How can I make subcommands for a slash command?
const data = [
{
name: 'tag',
description: 'create a tag',
options: [{
}
]
}
]
await client.guilds.cache.get(guildId)?.commands.set(data)
I want to have tag create, tag edit, tag remove, etc
options:
[
{
name: "subcmd1",
description: "Sub command 1 description",
type: "SUB_COMMAND",
options:
[
{
name: "channel",
description: "Select a channel for example.",
type: "CHANNEL"
}
]
},
...
]
Where sub command options are parameters (if you need them).
To understand nesting
thank you
I'm trying to use animated emojis in my bot but it is not working
setDescription
Anyone
is it a animated emoji
It is working when I write simple text but it is not working with this code
Yea
hmm
See this...it is working with Waao only idk why?@brittle oyster
is the bot in the server with that emoji?
Yes
hmm
The emoji is form that server itself
are u sure you have the correct id
ok
not a valid emoji then
In the above embed it is there
What library do you recommend for greater speed in my music bot?
Waao text
wdym
what language first
you need to actually get the emoji afaik
js
lavalink
It is there
Phantom you cannot get Ids using the method mentioned above on mobile
You need to be on PC
And the ID you are using is probably the message ID
I am on pc also.... side by side
You can also get the emoji from the client's cache with the id
Ohhhh
So how to get the emoji I'd?
Then type \:hay_fire1: and send it in the channel. It will automatically be sent as the ID in the channel, after that copy paste that ID
does discord bot maker host your bots for free?
no


so you host it?
yeah
@high crown the process should look like this
you have to host it yourself
You can also just copy and paste the same string in the chat box to get animated emojis if u dont have nitro
Also, is dbm discontinued?
@earnest phoenix
You have to do the other slash \
Wait
\:emojiName: was not working for me so after cussing my fate I did this....will it work?
yes it worked
thanks a lot guys
Nice job!
Please help! Someone is spamming my bot with an error and I have no idea where it is coming from. https://ch1ll.needs.rest/kv5dar1cm0a.png
Does anyone know how I could find the error using process?
send the full error and fix the bug then
If I have if elif and else then if I want to add another like cooldown cmd then how can I add 4th
err what
Hm wdym
can you send like a code snippet?
Hm
I don't understand your question
so you want to expand your if else chain?
Ya
you're using python right?
Like I have already used if elif and else
Yes
Oo
this is very basic python tho
you should probably first have a solid understanding of python
Ok ty
:D
has anyone seen a package that actually fulfils all requirements for npm package explorer
CommandInteraction {
type: 'APPLICATION_COMMAND',
id: '901858432888496149',
applicationId: '894599461735661578',
channelId: '893918781628370984',
guildId: '893491180820643860',
user: User {
...
},
member: GuildMember {
guild: Guild {
..
},
joinedTimestamp: 1633098756770,
premiumSinceTimestamp: 1633358046458,
deleted: false,
nickname: null,
pending: false,
_roles: [
..
],
user: User {
..
}
},
version: 1,
commandId: '901818245852586015',
commandName: 'tag',
deferred: false,
replied: false,
ephemeral: null,
webhook: InteractionWebhook { id: '894599461735661578' },
options: CommandInteractionOptionResolver {
_group: null,
_subcommand: 'create',
_hoistedOptions: []
}
}
So like:
switch(interaction.subCommand) {
case 'firstSub:
..
break
case 'secondSub:
break
...
yeah but they don't even show us how to use it
You gonna use the CommandInteractionOptionResolver
Looping through the options, for example
I'm glad I use detritus
for(const option of interaction.options.data)
{
if(option.name === "create")
{
...
}
}
good boy
Shhh Erwins
Djs interactions look way more complex and hard
and if you really wanna go pure discord api it ain't that hard too
Not much as python
I meant
Actually not, but also yes
If you understood how it’s built and how to access it it’s easy not to say logical
Are we hating on languages we don't know 
But it’s somehow less user friendly
Yes yes, snakes suck

imagine if everyone had to write their own rest API wrapper
there would be a dozen bots around
a dozen very efficient and well written bots
Would automatically sort out most of the shit
instead of thousands of shit bots
Aye
He's not being rude, he's speaking the truth
i can't help but agree with that
For example mine lol
Mine is very efficient
It never fails to reply with h
just becuase they've hacked together the api doesnt mean its well written 
example -> Most of the Discord.py forks with all sorts of monkey patching
Good I create a backup of my PHP framework 
So efficient
outdated humor
Just stole from dankmemer
Yep definitely well written
WARNING: ffmpeg: Unknown version string
WARNING: ffprobe: Unknown version string
While using https://npmjs.com/package/editly on heroku
and ffprobe?
ffprobe probably won't be necessary and is just warning you that one or the other is supported but none is installed
As they told you a few times already, be patient.
Saw you asking many times already, dude
There is a server always kicking my bot without getting it back
And code is true but all things showing undefined
In your event check if the guild is available.
That's a property in djs13
if(!guild.available) return;
Hmmm
And my bot started to slow restart after this server showed up
It's happening again
As I said might be an unavailable server for whatever reason.
I can help. How could I help you?
I have like code done but there is a error I can't fix
What's the error?
Couldn't resolve the user ID to unban
Okay, could you then show the code?
Ofc
const Discord = require('discord.js');
module.exports = {
name: 'unban',
description: "Ovo je _ping komanda.",
async execute(message, args) {
if(!message.member.hasPermission("BAN_MEMBERS")) return message.channel.send('You can\'t use that!')
if(!message.guild.me.hasPermission("BAN_MEMBERS")) return message.channel.send('I don\'t have the permissions.')
const member = message.mentions.members.first();
let memberTarget =
message.mentions.members.first() ||
message.guild.members.cache.get(args[0]);
if(!args[0]) return message.channel.send('Please specify a user');
let reason = args.slice(1).join(" ");
if(!reason) reason = 'Unspecified';
message.guild.members.unban(memberTarget)
message.channel.send("uspelo");
}
}
How do you execute that command? What is the first argument?
Well the member isn't cached anymore if you ban it off the server after a bot restart.
I am using discord.js version 12.5.0
You have to fetch the user object as he's not a member anymore.
Command should work like =unban members id
So you paste the user id to the command and dont mention it?
Yes
If so, fakes answer works
Only if it's a mention, not if it's just an ID
U can't metion banned person
message.mentions.members.first() OR message.guild.members.cache.get(args[0]);
I have both of that
U can't I tryed
BUT instead, as I already said, you need to fetch the user, not getting it from the cache
U can just paste id
Where do you fetch it? message.guild.members.fetch()?
Is it there anymore if the user is banned
It's only cached until the app restarts
Where do I fetch it and how?
Yea where do you fetch it, I dont think it resolves if you do message.guild.members.fetch()
np
Keep in mind that's a promise
And where do I put this?
You put it where you need to get the user
you need to await it or do .then
Could it work like this
const Discord = require('discord.js');
module.exports = {
name: 'unban',
description: "Ovo je _ping komanda.",
async execute(message, args) {
if(!message.member.hasPermission("BAN_MEMBERS"))
return message.channel.send('You can\'t use that!')
if(!message.guild.me.hasPermission("BAN_MEMBERS"))
return message.channel.send('I don\'t have the permissions.')
const member = message.mentions.members.first();
if(!args[0]) return message.channel.send('Please specify a user');
let memberTarget =
message.mentions.members.first() ||
await client.users.fetch(args[0]);
let reason = args.slice(1).join(" ");
if(!reason) reason = 'Unspecified';
message.guild.members.unban(memberTarget)
message.channel.send("uspelo");
}
}
But you need to get the client to this event
So you need to change the event handler you have
To pass through the client
Would it be easier to remove the user from the guild's bans
you only need the user id to do that
not the whole user
...
if(!args[0]) return message.channel.send('Please specify a user');
const memberTarget = await (message.mentions.members.length) ? message.mentions.members.first() : client.users.fetch(args[0], false, true);
if(!memberTarget) return // error couldn't fetch user
message.guild.members.unban(memberTarget);
fake what do you think
do guild.bans.remove(userId)
Hmm it's up to you.
Wouldn't it be easier
Using guild.bans.remove() seems to be easier, yeah
As the promise returns an error if the entered user resolvable is invalid or not banned.
Yea just what I was about to say
Don't need to fetch the user using that method.
Has anyone had issues with using the discord-rpc package on npm? I can get my RPC to work perfectly fine when I run it on my own computer, but when I try to run it on my VPS, I get ```
Error: Could not connect
at Socket.onerror (/home/opc/wafflebot-detritus/node_modules/discord-rpc/src/transports/ipc.js:32:16)
at Object.onceWrapper (events.js:520:26)
at Socket.emit (events.js:400:28)
at Socket.emit (domain.js:470:12)
at emitErrorNT (internal/streams/destroy.js:106:8)
at emitErrorCloseNT (internal/streams/destroy.js:74:3)
at processTicksAndRejections (internal/process/task_queues.js:82:21)
Oh...
Anyone know any solutions to this?
Nevermind
Turns out that's just not a capability of discord's rpc
Nice job figuring it out though
Took some research, I'll just have to take a different approach to this
lol somehow experienced this shit myself, too
The interaction I received through the event did expire before I could defer it

How is that even possible :D
okay
Almost happened 2 times close to each other
must be a cache issue
Yes
Do i just put / in the prefix
Yep
Oh okay
Do you want to see it?
Why not
Yay
Hey so I’m running into problems with node js it keeps making my bot unresponsive after 16 hours
Hello, how can I resolve this error? Is another way to check bot permission?
the message guild can be null, so typescript complains about it. Because you can send messages in DMs, then there wouldn't be message.guild
You need to either check if its null above or do message.guild?.me...
Ok, thanks
welcome to typescript
this is why i stopped using it
it slows down my productivity
but i don't know why i still have this error..
kind of defeats the purpose of js
Are you trying to register slash commands?
no, i try to make change nickname command
Oh, that just looked like it errored at the start so i thought you were registering
import { GuildMember, Permissions } from "discord.js";
import { ICommand } from "wokcommands";
export default {
category: 'Moderating',
description: 'Change Nickname',
minArgs: 2,
permissions: ['CHANGE_NICKNAME'],
expectedArgs: '<users> <nickname>',
callback: async ({ message, args, interaction }) => {
let nickname = args.join(" ");
const target = message ? message.mentions.members?.first() : interaction.options.getMember('user') as GuildMember
if(!target) return `You need to tag someone to change him nickname.`
if(message?.guild?.me?.permissions.has(Permissions.FLAGS.CHANGE_NICKNAME, true)) {
target.setNickname(nickname)
}
}
} as ICommand
this is my code
I think so... when i trigger the command error appear
Makes sense
Is the change nickname permission for changing others' nicknames
Or is it only for changing your own
That could be it
Nope his own
Yea so it still doesn't have permission if you only check for CHANGE_NICKNAME
hmmm
What you mean is MANAGE_NICKNAMES
Yea that is what you should check for
Nope
on bot role
The role position matters
Do you wanna change the nickname of others or only the bot?
If you are trying to change someones nick that is above the bot's role, you cant
change the nickname of others
is above member role
Yeah then it’s MANAGE_NICKNAMES
And you are trying to change a member's nick?
yes
And this "member" does not have any other roles above the bot role?
no
Could you send the updated code that still makes the error?
Look, i try to check if my verification it work, and it work. but when i put target.setNickname(), he say's dosen't have permission
....
ok
import { GuildMember, Permissions } from "discord.js";
import { ICommand } from "wokcommands";
export default {
category: 'Moderating',
description: 'Change Nickname',
minArgs: 2,
permissions: ['CHANGE_NICKNAME', 'MANAGE_NICKNAMES'],
expectedArgs: '<users> <nickname>',
callback: async ({ message, args, interaction }) => {
let nickname = args.join(" ");
const target = message ? message.mentions.members?.first() : interaction.options.getMember('user') as GuildMember
if(!target) return `You need to tag someone to change him nickname.`
if(message?.guild?.me?.permissions.has(Permissions.FLAGS.MANAGE_NICKNAMES, true)) {
target.setNickname(nickname)
}
}
} as ICommand
I think you need to do it like this: ```
if(message?.guild?.me?.permissions?.has("MANAGE_NICKNAMES")) {
target.setNickname(nickname)
}
(you don't have to pass the true as the second argument because it's default value is true)
You need the null coalescing operator only on the guild property
me property can’t be null
As well as permissions
Like that?
It can only be an empty array if you haven’t any permission
Well it'll complain :D
Only on guild?
Yes
I think it has to be on every if the one on the left has it
It actually does not make sense
I think I'll move to javascript, it's nonsense with this typescript :)))
Well I would say it is really good that you can see errors before you run the application
guild can also be null
Yes
guild yes, me not wtf
but if i remove .me another error's appear
Yea it has a problem
🤦♂️
Like on his screenshot permissions would be the issue
it doesnt get that you are trying to get a guild member
it onyl thinks that is a member object
message.guild.me is a Member object of the bot
so you'll have to get message.guild.me as GuildMember
and then you can check it's permissions
Yeah know how you feel 
oh
(message?.guild?.me as GuildMember)?.permissions.has("MANAGE_NICKNAMES");
Oh my ugly god
Almost forgot the ? :D
Never thought I would say this, but thanks for I’m using JS
That was not fun to troubleshoot when I first got it...
The error msg is not that clear
Remember to import GuildMember from discord.js
thanks
Did you get it working?
message?.guild?.me!.permissions.has("MANAGE_NICKNAMES")
```I believe works as well
Yea I started to think that aswell after you posted the screenshot, it shows that .me can only be GuildMember
whats the best way to do time based events for your bots ? like if I want my bot to send something 25 min from now. Do I just use setInterval (NodeJS)?
Ah yea
this is the witchery that I use const perms = payload.guild!.me?.permissionsIn((payload.message as any)?.channel)!;
But that's detritus
That looks worse than djs :D
Probably since they being checked each process tick
not really
ok, good, I'm doing something right
hmm
Why is python bad
do most of you guys use TS for bot development? I'm just using good old fashioned JS
But I do expect some slowdown if you plan to create thousands of it
TS is for people that dont want to learn JS
I use ts
You’re a Texan, you don’t count
And this is quite the opposite...
Agreed
yes that worries me, I don't think my bot will ever get that big, but the 4 years of software engineering school has taught me that this type of shit will not scale well. What I have in mind if my bot ever gets that big is to use a database and just have one setInterval running and update all the bots using one thread
but thats a later BlackDoom problem, current BlackDoom doesn't even have a verified bot yet
lowest value bugs found by type system. type system causes bugs
when you take a full accounting of types, they are just not worth it
That json guy is right
yeah, he created JSON and convinced people to switch from xml soap
my personal opinion is that Web was not made for Strong Typing
any time you try to shoe horn something into something that isn't accepting it is when you make unnecessary complexity
Might also be an idea to spread your workload into multiple threads later on
If you somehow notice a slowdown
The deno team stopped using typescript for their (internal) code even though deno is supposed to support typescript
It was too much brainfuck for them
yea thats also a good idea, I'm running everything from home now (I have my own server stack on a gigabit symmetrical network) but I think I would run seperate containers for my server with a load balancer instead of seperating out the threads
And yet it's written in rust... one of the more brainfucky languages out there.
All I like about typescript is the intellisense
same
i dont like the aggressive and petty type errors/warnings
it will refuse to compile if you forget to do one thing
actually it still compiles if you have errors
not for me
maybe you just haven't noticed it?
but intellisense with typescript gives you a false sense of security IMO
well if it's a syntax error then yeah
but if it's related to types then it should still compile
yeah types
it doesnt compile
i usually clear my dist folder too so it would be difficult to not notice
and besides the errors would be too annoying to just ignore
i used to go along with the flow of "ts is cool" but not anymore
slows me down too much
intellisense is cool though
you can get intellisense from jsdocs
annoying to do
another newbie question: If you make any changes to your bot, does it need to get approved again
there are editors that rename typescript as awesome intellisense powered by ai
/** parseInt
- {number} string
*/
¯\_(ツ)_/¯
and i do like strongly typed languages but trying to add strong and strict typing to a language that wasnt designed to be like that just makes it hard to use sometimes
yea, ai is one of those words that gets thrown around loosely
Has anyone else had an issue with node js just randomly taking your bot offline??
the devil is downloading
starting with strongly type: kind of hard but still doable
doing dynamic types for 2.5 years then moving to strongly: kill me already
i got used to it quickly
Provably an issue with your host
i mostly use c++ nowadays
Replit or heroku?
I have no host
yea I was gonna say host issues normally break stuff
I run everyone myself
even memory errors
Well then you turned off the bot or killed the process
No I didn’t it would work before I go to bed but when I wake up the bot is offline it didn’t throw any errors just went offline
what being an alpha male looks like:
I even have a batch to auto restart the bot upon error
use pm2
What does pm2 do if you don’t mind me asking
all this stuff
cry debate about it
is children a render prop in react
Thanks
See
All you're doing is changing the way the prop content is displayed
Isn't that what a render prop is supposed to do?
the render component is still handling the render, it's just passing it to the other component
you can just do <div className={classNames(styled.root, className)} />
what classnames do
nicely formats conditional classes
css modules is a pain though. So verbose for very little real benefit
i put logic there sometimes so i like having it ready
you can still do that with the next argument
classNames(staticClass, {
[dynamic]: condition
})
uhh ok if you like writing unnecessary objects
i use it whenever i need to change class names based off the state
that's old code
i use @media selectors now
idk chakra does a lot of these out the box and it's not verbose like this
100% agree
i was using material-ui
U use chakra too?
ya
I tried Bulma for a while and I love it for static websites
bulma is ok but I end up fighting the framework more than actually using it
Chakra's good for dynamic stuff and accessibilty
i dont see the point of a css library when you just end up customizing their default components anyways
cries in 66 line sass file anyways
right, chakra doesn't have much of an opinion on your design. And you can turn it all off very easily in places where it does
for me it's a css preprocessor than a framework with built in styles
Chakra uses emotion and they say it makes your website sorta slow
yeah it is a little chunky
chonky
they also don't support using the smaller version of framer-motion
which makes me a bit upset
but the developer experience is so good that it's worth it
Center component
I don't hate my life doing designs with chakra
Saves a lot of headaches
Stack components take care of RTL too
regular css
also we're talking about chakra which is more about accessibility
Sa
how do i format this so i can put multiple lines on the web page?
res.status(200).json({"line_one": "Im line one", "line_two": "Im line two"})
wtf is that
send more code
making an api, its a express server and idk how to format the json so it is like:
"line_two": "im line two"```
I don't think you can get it to multiple lines if you are only outputting json
It depends on the browser how it'll show it to them
Most browsers just dump the raw json so it will be on one line until the end of the screen
something like this https://api.alexflipnote.dev/
Maybe you dont give them json? Give them html with line breaks or something like that
ok
I'm sorry im wrong actually :D
Is it normal that I get '***' as project ID?
That section of the workflow is
# Push the Docker image to Google Container Registry
- name: Publish
run: |-
docker push "gcr.io/${{ secrets.GKE_PROJECT }}/$IMAGE:$GITHUB_SHA"
Or is it just to hide the secret
in the output
(github actions)
Yea I think they hide it
ok
What browser are you using
chrome
Of course you can
That doesn’t depend on the browser
You can return the raw string formatted
But is it still a json response?
Oh
Please explain it so Char can do it too
Firefox is formatting it
Just google JSON pretty print for JS
Im sure there’s a similar way doing it like with PHP
PHP 
Aye
Pretty-printing is implemented natively in JSON.stringify(). The third argument enables pretty printing and sets the spacing to use:
var str = JSON.stringify(obj, null, 2); // spacing level = 2
There you go
That format has nothing to do with the raw data
You should be able to view the raw data as well in Firefox
Looks like a wrong content type
eh
What does your code look like?
const text = {
"Test": ["Test", "Test2"]
}
// serialize JSON object
const str = JSON.stringify(text, null, 4);
// print JSON string
console.log(str);
res.status(200).json(str)
})```
Well it would make sense to do that automatically since res.json is used
Dunno express
ye it dose im pretty sure
That TS error didn’t make sense, too
:D
Sense and nonsense are close to each other
especially in this lang
I think you need to app.use(expres.json())
But that is usually used on the server when you expect json, not when you are responding with json
I'm not understanding what I need to put in the deployment name
https://github.com/5A-Informatica-IIS-Silva-Ricci/kubernetes-discord-bot/blob/main/.github/workflows/google.yml#L24
In this case the content type must be wrong or \n would be parsed as new line
I read about it, I think JSON.stringify() puts the \n things there
Here it says "the name of your deployment"
https://docs.github.com/en/actions/deployment/deploying-to-google-kubernetes-engine#creating-the-workflow
But I don't get what that is
Yeah it’s called pretty printing
If it has the right content type it will be printed fancy as raw data but still be regular JSON data
Doing that myself, too on my API
should i just send a html file
The screenshot I sent is pretty printing
you don't need to stringify it, res.json() does it for you
So its stringifying two times and thats what happens
so do i just type the json how i want it
Just don’t use json() as method on res
Then the type might be wrong
If you wanna have pretty printing
content type
Yes that’s what I’m saying for 5 min now
Set the content type to application/json
Manually
res.header()?!
Whatever idk express
use res.json() without stringifying the object and set the spaces however you like it using app.set("option", "value") https://safe.kashima.moe/7kpgkyrgwe2k.png
and it has been also confirmed that res.json sets the correct content type
yes, it does https://safe.kashima.moe/ujmah94vrtc4.png
so i do
app.get("/", (req, res) => {
const str = {
"Test": "Hi",
"Test2": "hi"
}
res.status(200).json(str)
})
?
res.json sets the correct content type, you dont have to do that manually.
oh ok
so its just:
const str = {
"Test": "Hi",
"Test2": "hi"
}
res.status(200).json(str)
})```
?
flazepe said you'll have to set the spaces using app.set
how
For example like this app.set("json spaces", " ")
That would use 2 space indenting
Do that outside the app.get
you could also just put 2 as value and it'll use 2 spaces
or "\t" if you want it to use tabs
However you like
used this, ty!
How can I delete a slash commands in discord.js v13?
Get its ID and send a delete request
client.application.commands.delete()
(if it’s a global command)
delete() takes the command ID as argument or the command resolvable
Thanks it’s working great now
\t is one character less than two spaces so it'll probably give a smaller response
My bot ideas are totally cringe
You people are gonna laugh
It’s a restaurant economy bot
My bot replies with h when someone says h and it's in 75+ servers
h
nice
seems like a useful bot
more useful than mine
lol
Sarcasm or real
Cool
Anyone know about adding a custom background image on the bot page? I'm adding the imgur link but it says only jpeg and png are accepted even though it is...
Hey I got a question if anyone can help
This should work for voting right?
do i need to authorize
import topgg
@client.event
async def on_dbl_vote(data):
bob = data["username"] + data["discriminator"]
if bob in daily_limit:
daily_limit[bob][0] += 1
daily_limit[bob][1] += 1
else:
daily_limit[bob] = [4, 4]
limit_file = open("daily_limit.json", "w")
json.dump(daily_limit, limit_file)
limit_file.close()
print(time() + " - " + bob + " - voted, daily_limit updated")```
please stop using a json file for a database 🙏 🙏 🙏
my bot is the first thing I've coded in python that's more than a few hundred lines of code, i'm just happy it doesn't explode whenever i use a command
Lol
i have an issue that when i restart my bot its automatically emitting guildCreate or guildDelete events
I'm assuming my code should theoretically work then, apart from being massively inefficient?
Maybe
I don't do python so just try it and see if it works
didn't even trigger the function 
im guessing i need to add this with my bot token?
bot.topgg_webhook = topgg.WebhookManager(client).dbl_webhook("/dblwebhook", "password")
await bot.topgg_webhook.run(5000)```
how do i vote again to test it?
That’s not an issue, those event are happening while your bot is offline or they are keep happening because of an unavailable guild.
just have it ignore that event when guild is undefined on that event
You should always check if a guild is available, in any event if you’re dealing with a guild
I think you already told him that before
This channel is just a continuous repeating of things
mmmkay my code still does absolutely nothing when someone votes
client.topgg_webhook = topgg.WebhookManager(client).dbl_webhook("/dblwebhook", "my bot token")
client.topgg_webhook.run(5000)
@client.event
async def on_dbl_vote(data):
# doesn't run```
pls help
my non techy friend really thinks mongodb is a json database
yeah 99% of people on discord use mongodb because they think it's a json datatabase they can use without getting yelled at
Anything that prevents me from using different data structures for different parts of the app is a win win for me
Imagine converting sql stuff to json so you can actually use it
afaik it's supposed to stink really hard
am i simping for mongodb
Another reason is... heroku does not support sql and people are broke to buy a vps
we're having a really really difficult time migrating the shitty mongodb database for topgg to postgres because there's no data validation and every once in a while we get a field on a record that should be a boolean like approved for bots that is a string for no reason
you can't make assumptions on the data you're working with because there's no data integrity
a language that doesn't check types passing random shit into a database that doesn't check types. What could possibly go wrong
the only reason i can see myself using mongodb is if I'm building something rly quick that needs a little bit of persistence. And I only do that because of mongodb atlas, not because mongodb is actually good
easy is better than efficient

and mongoose exists
you can't hate on react for not having state management built-in because they know the community can make one better
mongoose is one of the worst ORMs I've ever used
you can do validation at the application layer but you still don't have integrity. You can't safely do migration between schemas because the database doesn't have info on what the schema looks like in the first place lmao. Also there's basically no tooling for migrations to begin with
mongodb people just like to pretend they don't have a schema for some reason
honestly mongodb is an L you take for scalability, not a tool that makes your life easier. And it's not even necessarily good at that either
also state hooks and contexts exist
I just use mongodb bc of the free offered atlas
it's not that heroku doesn't support sql, it's just that you cant use file-based dbs on it
normal externally hosted dbs work just as fine
It was sarcasm my high techy(no) friend
heruko has a postgres add-on
just use supabase
it provides a postgres instance for free
lol
but with a 500 mb limit but I personally don't store that much anyways
for bots that aren't on a giant scale that store server settings its perfect
you might as well just setup a proper database if you're gonna go down that route
ig
how do i set the body of a website to an image
it ain't about you
css background-image?
no, like how discord do it. so you can pate the url: https://cdn.discordapp.com/attachments/895400729978736670/902188027642773534/discordblue.png and it will display the image and you can use it in embeds and stuff
You mean like this: https://discord.com/
That image?
If you want to do embeds on your website:
- Send a request to that link and check the content type header
If it's an image (res.headers['content-type'].test(/^image\//)) - Put an <img> under the message with the src set to the url
You want the entire website to be the image?
yes
set the background image of the body element with css
so the link is the image,
so in an embed i could do;
.setImage("https://cdn.discordapp.com/attachments/895400729978736670/902188027642773534/discordblue.png")
umm
why don't you just open the image link
your browser will already display it in full size
no, im making an api and i want it to display an image like that, thats just an example.
anyways
#some-element {
background-image: url("some url");
}
that's the css you need for it
wait wait wait, does the api give html or raw image data?
raw image data
@spark flint You can force a cache refresh on chrome with ctrl + shift + R i think
ah ok
Apologies quick question:
Im new to Javascript, and currently trying to work with coding a website in it.
My issue is the following
I have this code on my website
<script type="text/javascript">
let progress = document.getElementById('progressbar');
let totalHeight = document.body.scrollHeight - window.innerHeight;
window.onscroll = function(){
let progressHeight = (window.pageYOffset / totalHeight) * 100;
progress.style.height = progressHeight + "%";
}
</script>
When moved to the javascript.js file, the code doesnt work anymore, im confused as to why.
any help would be appreciated
<script type="text/javascript" src="main/js/javascript.js" ></script>
This is the link i did to the javascript file.
really ?
is there a way that i can turn a canvas image into a link
no, but u can save it as a file and serve it like any other file
or just upload to discord
its not for a bot, its for a web server
You can convert it to buffer and then convert that buffer to base64
I'm looking to use UptimeRobot to keep track of the status of my discord bot, I already use it for my webserver, but how would display the status of my discord bot instead?
Well your bot needs to continuously answer requests to make it possible to check if it’s alive or not.
I guess the easiest way is to listen to HTTP requests and answer them with a 200 status code
If the bot is down it doesn’t answer anymore which will be noticed as down time
But I’ve got no clue if your service supports that.
That’s something you will have to find out
@boreal iron Issue is, i'm already doing that for my webserver
I don't want to have to create another web server in the code of my bot
Since it already has one
If so what prevents you from sending requests to it, if it already exists?
You can only preview if bot is online or offline
It doesnt fetch server Informations just checking if its available
Because i'm already pinging the server to see if that is up and running
Which does not account for my discord bot
If the webserver code is part of your bot, it also means the bot's running.
Nope
Running the webserver and bot separately
I don't want to have to create another web server in the code of my bot
You need to respond to requests in any way.
Looking on your services website there isn’t much more available to use in your case
Also why shouldn’t a simple and lightweight webserver be a problem?
Define a specific port for it and configure your firewall that only uptime robot can access it
Therefore no spam and/or performance issues will appear
you can also tunnel it w ngrok or cloudflare tunnel
how do i make an express endpoint that i can do /magik/<user id> and it will distort the user with the id said in the url's profile pic and then return that image so someone could send it in an embed,
i already have the part where it finds all the info about the user using the id and gets their profile pic.
just a heads up, that's bound to fail
discord hates urls that return different results each time it's accessed
ohh
so, like, if the user changes avatar and retry it'll still show the old avatar
even after a long wait?
no
i don't remember what the cache expiry is
however
you can append a cache buster to the url, forcing the discord to recache the image from the url
should i just do /magik?<image url>?
okay, either way, how do i do that lol
just grab the param and return a blob
like
?id=123456789 means param id will have value 123456789
grab the user avatar using that id
then set response header content-type to image/jpg (or whatever format u want) and put the modified image bytes into the body
it'll result into something like this
except with a different image obv
in this example, I use two params (anime and name)
im just not sure how i would change the image and then send it back
THAT'S a whole new issue
ah. my bad
you'll want to use canvas for that probably
give it a search on how to process images using it
okay
i know a lil bit of canvas, its mainly getting the image from it and then sending as the response
Nice,sadly i can't find any integration for my actual projects.Since i need the changestream functionality,which mongodb has.
So I'm trying to make a slash command I have this code but I don't know what to do with it:
const { SlashCommandBuilder } = require('@discordjs/builders');
const data = new SlashCommandBuilder()
.setName('log')
.setDescription('logs some info.')
.addStringOption(option => option.setName('input').setDescription('Enter a string'))
.addIntegerOption(option => option.setName('int').setDescription('Enter an integer'))
.addNumberOption(option => option.setName('num').setDescription('Enter a number'))
.addBooleanOption(option => option.setName('choice').setDescription('Select a boolean'))
.addUserOption(option => option.setName('target').setDescription('Select a user'))
.addChannelOption(option => option.setName('destination').setDescription('Select a channel'))
.addRoleOption(option => option.setName('muted').setDescription('Select a role'))
.addMentionableOption(option => option.setName('mentionable').setDescription('Mention something'));
then:
client.on('interactionCreate', async interaction => {
if (!interaction.isCommand()) return;
const string = interaction.options.getString('input');
const integer = interaction.options.getInteger('int');
const number = interaction.options.getNumber('num');
const boolean = interaction.options.getBoolean('choice');
const user = interaction.options.getUser('target');
const member = interaction.options.getMember('target');
const channel = interaction.options.getChannel('destination');
const role = interaction.options.getRole('muted');
const mentionable = interaction.options.getMentionable('mentionable');
console.log([string, integer, boolean, user, member, channel, role, mentionable]);
});
But I'm almost certain I'm missing a step because it doesn't show up
You have to actually post the slash command as a guild or global command
how do i?
Post slash command with options
client.application.commands.create({ name, description, options });
ok and for a guild client.application.guild("<id>").commands.create({ name, description, options });?
i still do not see
Need to see your code
client.once('ready', () => {
const data = new SlashCommandBuilder()
.setName('log')
.setDescription('logs some info.')
.addStringOption(option => option.setName('input').setDescription('Enter a string'))
.addIntegerOption(option => option.setName('int').setDescription('Enter an integer'))
.addNumberOption(option => option.setName('num').setDescription('Enter a number'))
.addBooleanOption(option => option.setName('choice').setDescription('Select a boolean'))
.addUserOption(option => option.setName('target').setDescription('Select a user'))
.addChannelOption(option => option.setName('destination').setDescription('Select a channel'))
.addRoleOption(option => option.setName('muted').setDescription('Select a role'))
.addMentionableOption(option => option.setName('mentionable').setDescription('Mention something'));
console.log(client.application.commands.create(data));
console.log('Ready!');
});
output:
Promise { <pending> }
Ready!
wdym?
module.exports = {
"name": "join-channel",
"type": 1,
"description": "Sends auto Mesage when someone joined.",
"options": [
{
"name": "options",
"description": "What you want to do?",
"type": 3,
"required": true,
"choices": [
{
"name": "Set",
"value": "set"
},
{
"name": "Reset",
"value": "reset"
}
]
},
{
"name": "channel",
"description": "Choose a channel",
"type": 7,
"required": false,
"channelTypes": ['GUILD_TEXT'],
},
],
async run(client, i, lang, options)
oh i will get
and
const commands = fs.readdirSync(`./commands/${dir}/`).filter(file => file.endsWith(".js")).forEach(async cmd => {
let file = require(`./commands/${dir}/${cmd}`);
let name = file.name
let desc = file.description
let options = file.options
commands.crete ({name: name, description: desc, options: options})
@earnest phoenix now I'm confused
Why
I have no clue what you're talking about
Dont you try to add options?
gives me the json:
{
"name": "log",
"description": "logs some info.",
"options": [
{
"type": 3,
"name": "input",
"description": "Enter a string",
"required": false
},
{
"type": 4,
"name": "int",
"description": "Enter an integer",
"required": false
},
{
"type": 10,
"name": "num",
"description": "Enter a number",
"required": false
},
{
"type": 5,
"name": "choice",
"description": "Select a boolean",
"required": false
},
{
"type": 6,
"name": "target",
"description": "Select a user",
"required": false
},
{
"type": 7,
"name": "destination",
"description": "Select a channel",
"required": false
},
{
"type": 8,
"name": "muted",
"description": "Select a role",
"required": false
},
{
"type": 9,
"name": "mentionable",
"description": "Mention something",
"required": false
}
]
}


