#djs-help-v14
79229 messages · Page 80 of 80 (latest)
you should log attach.url and see if thats valid
i did everything i upload from computer as png and still
it must this as url?
Is there a way to get the original message from this setup?
Message with buttons --(button click)--> Interaction --(button click)--> edit the message with buttons
ButtonInteraction.message is the message the button is on
ButtonInteraction#message discord.js@14.26.4
The message to which the component was attached
Oh, didn't realize that. Thanks
If you're looking to edit the original message, you should use <ButtonInteraction>#update()
could you help me pls
If you don't get a response, either wait or make a #986520997006032896 post so that it doesn't get lost in the chat...
No just console log it. See what you get
Is there a way to disconnect the bot (itself) from a voice channel without needing any permissions?
Just end the voice connection
okay, also is the guild.members.me.voice.channel is always in cache?
Yes, as long as you don’t influence it otherwise
You shouldn’t be messing w/ any channels cache anyways
Yes, I was just trying to access that, assuming it will be in cache always!
CombinedError (2)
Received one or more errors
1 ExpectedValidationError > s.instance(V)
| Expected
|
| Expected:
| | [Function: ButtonBuilder]
|
| Received:
| | undefined
2 ExpectedValidationError > s.instance(V)
| Expected
|
| Expected:
| | [Function: ThumbnailBuilder]
|
| Received:
| | undefined
at _UnionValidator.handle (C:\Users\shong\Kick - BOT\KickBot\node_modules\@sapphire\shapeshift\dist\cjs\index.cjs:1965:23)
at _UnionValidator.parse (C:\Users\shong\Kick - BOT\KickBot\node_modules\@sapphire\shapeshift\dist\cjs\index.cjs:972:90)
at SectionBuilder.toJSON (C:\Users\shong\Kick - BOT\KickBot\node_modules\@discordjs\builders\dist\index.js:2536:37)
at C:\Users\shong\Kick - BOT\KickBot\node_modules\@discordjs\builders\dist\index.js:2237:64
at Array.map (<anonymous>)
at ContainerBuilder.toJSON (C:\Users\shong\Kick - BOT\KickBot\node_modules\@discordjs\builders\dist\index.js:2237:35)
at C:\Users\shong\Kick - BOT\KickBot\node_modules\discord.js\src\structures\MessagePayload.js:151:46
at Array.map (<anonymous>)
at MessagePayload.resolveBody (C:\Users\shong\Kick - BOT\KickBot\node_modules\discord.js\src\structures\MessagePayload.js:150:49)
at ChatInputCommandInteraction.reply (C:\Users\shong\Kick - BOT\KickBot\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:191:56)
(node:10972) Warning: Supplying "ephemeral" for interaction response options is deprecated. Utilize flags instead.
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
you have a section with out a assessory
likely line 131-140
is there a way to "mute" someone in a regular voice channel without server muting them or changing channel permissions or giving roles?
a bot i know does it but can't work it out so i'm asking if theres an official way of doing it
are you talking about a clientside mute? like for you only and not everyone?
kind of? it prevents you from speaking and shows you're muted to other people but it doesn't change channel permissions or roles for the user and doesn't server mute
isnt that just server mute?
like the self mute? I don't think a bot can do that to user, only server mute
theres server mute but then theres a different kind of mute, I think the bot i described uses some illegal means of doing it but basically it literally looks like you muted yourself on my end but you didn't the bot prevents you from unmuting but theres no visible channel permission or role permissions that were changed.. its weird
"Þ¥¿????舐╟ اŮñâmå•©ðsžšåÞя╟ ▀????Þ¥¿???? ©Ř§Ů— £╟舐—� ¶????½ ©舐¶—舐—ðsžšåÞя舐 £▀ا٩ñâmå•ا٩¶Ř§Ů½ æØ¢Ã 舐Þ¥¿Ř§Ů—. ▀ðsžšåÞяا٩ —舐Þ¥¿Þ¥¿ðsžšåÞя©. ▀????½ 舐¶ £½ —舐 ▀????Þ¥¿????� اŮ£¶ðsžšåÞяÞ¥¿Ř§Ů© ½ 舐¶� æØ¢Ã£☒اŮ▀£ £¶� ¶ðsžšåÞя©ðsžšåÞя© Ř§Ů½ � 舐????©. ╟£ðsžšåÞяا٩ ☒舐©—اٻðsžšåÞяÞ¥¿ðsžšåÞя╟� 舐Þ¥¿Ř§Ů© 舐— 舐æØ¢Ã舐©—£© ðsžšåÞяÞ¥¿Þ¥¿Â£╟¶ ????ñâmå•舐� ñâmå•ðsžšåÞяðsžšåÞя© ½ اٻ‚� ☒舐‚�اٶðsžšåÞяÞ¥¿Â£ ©舐╟� 舐ðsžšåÞя 舐æØ¢Ã舐©—£© £½ —舐 ½ Ř§Ů©Þ¥¿ ½ ????½ áÍÞæðsžšåÞя©—????. ðsžšåÞя©¶舐 —Ř§Ů½ ¶Ř§Ů▀ðsžšåÞя½ —� Þ¥¿????舐╟ ½ 舐☒ ▀£ñâmå•اٻðsžšåÞя© ¶????½ ©舐¶—舐—ðsžšåÞя舐� Þ¥¿舐???? ????¶Ř§Ů ╟????Þ¥¿Þ¥¿Ř§Ů© اŮñâmå•©ðsžšåÞя╟� 舐æØ¢Ã舐— ©ðsžšåÞя©¶Ř§Ůñâmå•اٗ 舐????© ñâmå•ðsžšåÞяðsžšåÞя© Ř§Ů½ £½ —舐."
- wise words from discordjs
Shitpost somewhere else
where did MessageFlags and ApplicationCommandOptionType go? it was there just a month ago...
is it not there? what version u on
14.26.4
might be why idk am on 14.25.1
They still exist and didn't go anywhere
hmm, well import { ApplicationCommandOptionType, MessageFlags } from "discord.js"; no longer works
What doesn't work about it? Do you get errors or does your IDE simply believe it can't find them?
my ide certainly thinks its no longer there, but all ive done is updated npm packages
Restart ts-server if that's VSCode. If it's webstorm or a different IDE from the same company: they have issues with finding re-exported stuff in djs. If the error doesn't exist when you run the code you know it's an IDE issue
ah thanks that fixed it :) didnt occur to me it might be ts server problems because i literally just opened vscode
with discordjs/ws, when should i use
parentPort?.postMessage({
type: 'dispatch',
shardId: shard.id,
event: payload,
});``` and when should i use
```ts
redis.publish(
'worker',
JSON.stringify({
type: 'dispatch',
shardId: shard.id,
event: payload,
}),
);```
-# basically im asking when its good to send events w redis pub/sub and when the normal parent port way is already enough
Use parentPort.postMessage() if your shard/worker is just sending events back to the main node process. That’s enough for normal worker
Use redis pub/sub if other separate processes, containers, or services need to receive those events too.
So basically, same app = parentPort, distributed/multi-process = Redis.
ah ok, thanks for clarifying!
👌
ig its also worth to ask when i should have the dispatch as a event to forward and when i should have it on the shardCallback
put dispatch handling in shardCallback when the event only matters to that shard/worker directly.
forward dispatch events when somet out side the shard needs them main proc etc
shard-local logic = shardCallback
app-wide/ external logic = forward the dispatch
I know, but what i'm talking about looks like the folloowing image but doesn't change the channel permissions or give the user role, or actually server mute them, its not red but it mutes the person via the bot, was wondering if this was actually possible via discord.js or not because a bot i know actually does do this
so if i just send the events back to the main thing to use client.emit, i should just forward, right?
-# im kinda confused, srry
yeah exactly.
in ur case gateway worker gets event > forward to main > main calls client.emit
if the worker is only receiving gateway dispatches and your main process is the thing that turns them into client.emit then you should forward them back to the main process f
anything else u need lmk
something thats not very related to workers now, how should I make a resharding system with discordjs/ws? i never made one before so im quite clueless
-# not asking for u to make the code for me, just wondering on how exactly i should make it
ill msg u
kk
Do you have it installed to your account with some extra scopes?
Because the only way to mute yourself is to mute yourself, and besides you doing it manually it's possible to do it via RPC, but it's not that simple as "just do it differently"
please don't drag people away into DMs like that
we have #1081585952654360687 for things like that, and keeping it in the server allows more eyes to look at the issue
its his choice to answer my message.
this is a help channel, keep the helping here it might help others
me sharing loads of "my" code in this channel wasnt my idea i was trying to help a certain person.
How can I access my client.emit() function from a separate file I am requiring my client from?
app.js
const client = { /* intents & partials */ }
module.exports = client;
streams.js
const client = require('../app');
client.emit('message', 'a message');
message.js
module.exports = {
name: 'message',
async execute(msg) { /* logic */ };
};
TypeError: client.emit is not a function
just import the client in the file?
sorry, updated my message.
if im not wrong just doing require('app') will just check for the npm package. youd have to import by file location so something like require("../client")
right I have it requiring my app.js file using require("../app") but for whatever reason it isn't including the bot events I have configured 😅
oh ok i see now you edited the message. does that work now?
It does not 😐
what djs version are you on
I am on v14. This is the structure of my app.js file looks like: https://pastebin.com/raw/XgGsu6Lt
You can export your code from your file like
module.exports = (client) => {
//code…
client.emit();
};
And then on require pass the client as argument: require('./file')(client)
I'll give it a try 👍
I changed my exports to module.exports = (client) => { client.emit() }; inside of the app.js and imported it with an error 😅
ReferenceError: Cannot access 'client' before initialization.
Uhh, you do module.exports in your streams.js and then require it inside your app.js 😅
no, not installed to my account, it was added to the server long before that was a thing
like
//app.js
const { Client } = require('discord.js');
const client = new Client({/*pass your options...*/});
require('./file.js')(client);
//streams.js
module.exports = (client) => {
//your code here...
client.emit();
}
i would suggest you to wrap everything in a function attached to client like client.yourfunction = function() {/*your code...*/ client.emit()}. that way you basically init your file, its attached to the client and you can call it whenever and whereever you want as long as you have access to the client.
Believe I resolved the issue without having to define an additional client inside of my expressJS middleware file(s). The issue was I was calling my streams.js function before the client was actually exported.
No, RPC has existed for a long time
Long before interactions have started existing
Tbf I'm curious what are you actually describing, but at this point it's not d.js related
rynobot is the bots name that has such feature, its used in their queue system but yeah was only wondering if it was possible through d.js
I mean, d.js is just using discord's bot API
To figure out if you can do it via d.js, first thing is to figure out what it's doing
yeahhhh.. no idea whats its doing cos it isn't changing permissions nor adding roles nor server muting so its some funky thing going on haha
bit confused and this is probably not where i should ask it but i dont have many other options anymore
But I've found this to be a pretty knowledgable server about apps, so maybe I'm wrong?
you gotta give more info than that
What more info is there to give?
so you just tried to create an application on the discord dev site and it says missing access thats just it?
Yes
if thats the case, #useful-servers message will help you better. this is just for discord js
im banned from that server
and i dont know any alternative
if there's any other server besides the one you linked lmk
well i cant unfortunately help you better with this cuz thats not enough info to help you
okay hold up you want like an image?
anything that gives more info
okay so ill get you an image rq
Where does it say this?
The dev portal
Is ur email verified?
yes?
if you dont verify your email your account is automatically deleted after a bit i think
Can’t think of why else you can’t create an app
should I try my alt?
(i do feel like this is the wrong channel for this type of question still)
Well, it’s the wrong server
Is there any alternative that isn't ddevs?
Dapi prob
I was considering that one
lowkey
I was also considering trying town hall
But I'd probably get ejected to DDevs if I ask there
Never heard of town hall tbh
- it was recent. like. recent. literally today
- it was very justified imo. they wouldnt let me back in for at least a while
not going into this here, this is absolutely not the place for this type of discussion
either way, ill go to dapi. thank you!
Does booster role return "managed" as true?
Role update fires for each role that was affected
I don’t think the Discord app can create a role with a raw position
ah okay i just leave as that for now
Bots can, but even then usually opt not to since it’s easier just to update the raw positions to match the desired ones
Yes
can i get a modal submit field value without it erroring if the modal doesnt have that field
Yes dont use the methods but just find in interaction.fields
You could also try-catch the get. That's what errors are for: to be caught and handled, not to annoy you
Hi,
263 | }
264 | };
265 | const timeout = setTimeout(() => {
266 | this.client.removeListener(Events.GuildMembersChunk, handler);
267 | this.client.decrementMaxListeners();
268 | reject(new DiscordjsError(ErrorCodes.GuildMembersTimeout));
^
error: Members didn't arrive in time.
code: "GuildMembersTimeout"
at <anonymous> (/home/debian/wheel-discord-bot/node_modules/discord.js/src/managers/GuildMemberManager.js:268:16)
Bun v1.3.1 (Linux x64)
```What causes this error ?
Thanks
Discord introduced a rate limit on requesting all guild members (once per 30s per guild).
- You will have to update your code accordingly to make sure this doesn't affect your app.
- Look for instances of
guild.members.fetch()with no user ids. - Starting in version 14.25.0, discord.js rejects the returned Promise and exposes details in
error.data.
-# If you confirmed this cannot be the reason, you can find other caveats in our guide
.
Is there any test framework for Discord bots out there? Couldn't find anything that's somewhat maintained
Are you intending on testing the discord api, or your bot's code
The former makes no sense, and so there isn't much stuff to test bots as a whole
just make a test server to test your bot @dry flame
@loud quartz @tardy sable I am looking to test my own bots, not the API itself. I think it would be useful as an integration test suite
yh why not just make a test server for it?
Yeah I do that, but it's a process of testing every command/functionality manually and I was wondering if there was some way to automate it
no i dont think theres some automation for it and tbh its always better to see the testing for yourself
Then cut out the API from the process
You're not trying to test if your bot makes the api request correctly and if discord api responds to you correctly
All you're trying to test is if your bot's code generates correct response for the given input
It's easier to do that if you don't have your Command.execute() send responses directly, but have it only generate content for the response, that is then sent by the command handler or whatever
This way you merely check the execute method, like it's supposed to be
Ok yeah this makes sense, so unit testing of my app's controllers is the only thing I should worry about
quick question:
with channel.send(..), can i send a message containing mentions that wont ping?
tag suggestion for @cunning thunder:
You can control which entities receive notifications via the allowedMentions option. You can:
- Set a default on the client
- Set for a specific message
- Use the
repliedUserkey to disable in-line reply mentions
{ ..., allowedMentions: { parse: ["users", "roles"] } }
so this should be the thing i want?
channel.send({ message: "message", allowedMentions: { } }) ? correct me if i am wrong please
(since all are optional)
or would i need to parse an empty array here?
yes that wont ping anything
tysm!
how to get the command name from a slash command response, cant find it in MessageInteractionMetadata
Name has been removed from the metadata. You would need to fetch the command data to get the name
To install run: npm install discord.js
- Documentation: learn more
- Guide: learn more
Please add the following code to your code base outside of any other event listeners and provide the full log output relevant to your issue.
client
.on("debug", console.log)
.on("warn", console.log)
- Note: if you initialize your Client as
botor other identifiers you need to use these instead ofclient - If the output is too long to post consider using a bin instead: gist | sourceb.in | hastebin
@tawdry girder hi there, please use #app-commands for personal usage, thank you!
way to combain these into one then spearate files
i dont really suggest combining them
is so i dont have 30-50 files in one folder lol
you can split the files up into categories, which you can then adjust you event handler to work with after
Event Handling
Node.js uses an event-driven architecture, making it possible to execute code when a specific event occurs. The discord.js library takes full advantage of this. You can visit the Client documentation to see the full list of events. This page assumes you've followed the guide up to this point, and created your index.js and individual slash commands according to those pages. At this point, your index.js file has listeners for two events: ClientReady and InteractionCreate.
?
fs.readdirSync("./src/events").forEach(function (f) {
if (fs.statSync(`./src/events/${f}`).isDirectory()) {
return fs.readdirSync(`./src/events/${f}`).forEach(function (x) {
bot.on(
x.split(".")[0],
require(`./events/${f}/${x}`).bind(null, bot, con, cfg)
);
});
}
bot.on(
f.split(".")[0],
require(`./events/${f}`).bind(null, bot, con, cfg)
);
});```
this fine
i personally recommend the guide.
especially for organizing your files better for events
Your Talking About this
const { Events } = require('discord.js');
module.exports = {
name: Events.ClientReady,
once: true,
execute(client) {
console.log(`Ready! Logged in as ${client.user.tag}`);
},
};```
^
ah, youre referring to the guide then?
i recommend you use the guide’s event handler for better organizing your event files
that’s my point
so thatconst eventsPath = path.join(__dirname, 'events'); const eventFiles = fs.readdirSync(eventsPath).filter((file) => file.endsWith('.js')); for (const file of eventFiles) { const filePath = path.join(eventsPath, file); const event = require(filePath); if (event.once) { client.once(event.name, (...args) => event.execute(...args)); } else { client.on(event.name, (...args) => event.execute(...args)); } }
yes
whats the diffrence dont see much
it’s completely different than your handler, i’m saying to use what the guide has for organizing your files
it’s your choice though since you asked about combining events, which i don’t recommend.
this is just my recommendation
if (fs.statSync(`./src/events/${f}`).isDirectory()) {
return fs.readdirSync(`./src/events/${f}`).forEach(function (x) {
var event = require(`./events/${f}/${x}`);
bot.on(event.name, function (...args) {
event.run(bot, con, cfg, ...args);
});
});
}
var event = require(`./events/${f}`);
bot.on(event.name, function (...args) {
event.run(bot, con, cfg, ...args);
});
});```this works great for my use
okay if it works then thats great!
dont really see any different on docs to that so should be fine
if you read the code you'll see the difference
what one lol more then one haha
from the guide, yes
so this then
fs.readdirSync("./src/events").forEach(function (f) {
var event = require(`./events/${f}`);
if (event.once) {
bot.once(event.name, function (...args) {
event.run(bot, con, cfg, ...args);
});
} else {
bot.on(event.name, function (...args) {
event.run(bot, con, cfg, ...args);
});
}
});```
that's not what the guide is suggesting. that's your own code
if you don't want to listen to my suggestion, that's fine. you can do whatever you want
im just trying to suggest ways you can organize your code better
Message#components discord.js@14.26.4
An array of components in the message. This property requires the GatewayIntentBits privileged intent in a guild for messages that do not mention the client.
i have looked at it and Dont see any different in the code the exact same as the one
@rancid hare hi there, please use #app-commands for personal usage, thank you!
the code you sent is not the same as the one that the guide has. it’s your choice to use it or not.
we’re really going in circles here
this is the same exepect fromthe .js which i dont need
please use whatever you want
no saying that just dont see the change in what you mean
seems like you edited your message to match what the guide has, which is what i was suggesting
so, please use whatever code you want, i can only suggest so much
this what i did have now got
fs.readdirSync("./src/events").forEach(function (f) {
var event = require(`./events/${f}`);
if (event.once) {
bot.once(event.name, function (...args) {
event.run(bot, con, cfg, ...args);
});
} else {
bot.on(event.name, function (...args) {
event.run(bot, con, cfg, ...args);
});
}
});```
suggestion more diffrent saying what is the problem
thats fine works any way and wont need change so its fine
but you didn’t seem to listen to my suggestion based on your original question, this is why can’t help anymore. good luck!
In the TextInput Style class of modals, in the short and paragraph fields, do they have a character limit?
yes, 4000 characters
Ty.
oh what, i dont see that channel on my left
k now i do nvm
thx
i can do
const overwrites = channel.permissionOverwrites.cache.get(guild.id);
const allow = overwrites.allow
const deny = overwrites.deny
but how to check the null ?
if it's not allow or deny
it won't be present in either of those bitfields
uh oh
No, that’s actually how you find such bits
inherit = ~allow & ~deny
my message was in regareds to a crypto scam that was sniped faster than i could tag mods
What's the AVATAR_RATE_LIMIT?
avatar[AVATAR_RATE_LIMIT]: You are changing your avatar too fast. Try again later.
i think its around 2 per hour
Thanks
In the slash commands docs, can someone tell me where the execute method comes from? I cant find anything about it
execute is a user built function it is not part of the library
it is in the guide but not the library
async execute(interaction) {
}```confused how this is valid syntax if we arent declaring it as any kind of function or arrow function here or elsewhere
Creating Slash Commands
Discord allows developers to register slash commands, which provide users a first-class way of interacting directly with your application. Slash commands provide a huge number of benefits over manual message parsing, including: - Integration with the Discord client interface. - Automatic command detection and parsing of the associated options/arguments. - Typed argument inputs for command options, e.g. "String", "User", or "Role". - Validated or dynamic choices for command options. ...and many more!
You should re read this page of the guide
also worth mentioning since you're asking specifically about js syntax: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_objects#defining_methods
it's the latter syntax in the example, but async
though reminder that further questions about js and syntax are better suited to #1081585952654360687
Okay i get it now, thats all i need thanks.
No key:value pair confused me.