#Thx for your help
1 messages · Page 1 of 1 (latest)
I want to check if there was a rate limit for my request, and if is, don't send the request and just reply to the user. Is this possible?
Basic message ⤴️
I'm sorry, after a good while of research I'm still stuck :/ @blissful zenith
I understand the general idea but I have no idea how to apply this to my bot :/
In Client constructor pass rest: {rejectOnRateLimit: ['/channels']} if you want it to reject on all ratelimits for channels endpoint. You can instead also pass a function that gets the whole RateLimitData and returns true or false to indicate whether it should reject or not (in which case it would queue as usual)
For example checking ratelimitData.route starting with /channels and .method being PATCH
Thanks for your answer, I'll try to figure it out 
So now when I try with this, so I can change my channel name twice, the third time, rather than having no console error and interaction failed, I always get interaction failed + my bot crash .
We agree that with just this, if the bot didn't crash, after 10 mins nothing would happen?
@blissful zenith 😦
You need to catch the rejection on the edit of your channel and interaction.reply in the catch accordingly
As that’s how you can check if you got ratelimit on that route
Thx 4 all
Hi, I need a little help, I am looking to create a real time channel/role log server.
Luckily discord offers this natively with the templates, now I would also like it to be updated in real time, I found the .sync() function in the docs but impossible to make it work, I must not understand something ...
Show your code.
Uch I just deleted it, but very concretely:
The basic idea is to synchronize the two servers in real time (categories and channels included). Messages not included.
For that I thought I was going to use the discord templates, so I create a template by hand and behind I want the update with each creation of channels / modifications.
So I audit the events, that's good. All that remains is the "call" of the synchronization function
(And the function i just see : https://discord.js.org/#/docs/discord.js/main/class/GuildTemplate?scrollTo=sync)
const { ChannelType, Client, EmbedBuilder, Guild, Channel } = require ("discord.js");
module.exports = {
name: 'channelCreate',
/**
*
* @param {Channel} channel
* @param {Client} client
*/
async execute (channel, client) {
if (channel.guild.id === client.config.guild.principal) { // Detect if a channel is created in principal server
channel.guild.sync(); // If true, call the function
} // (But that's probably not what I should call it)
},
};
Is there a way in the discord js API to automate this action?
^^
You talk about two seperate things there: a template is made from a current guild Lay-out and can be used to create a new guild out of it. You can sync your guild template to push changes in your guild to the template. But you can’t sync an already existing guild to match the template later on
Ah 😦
When I post an embed with bouttons, if i edit it when i click on button with that, it works.
const AntiFail = new EmbedBuilder()
.setTitle(`:warning: SOUHAITEZ-VOUS VRAIMENT VOUS FAIRE REMBOURSER ?`)
.setColor("#ffaf2e")
.setFooter({text: `La question vous est posée afin d'éviter la création de tickets inutiles...`})
const TicketActions = new ActionRowBuilder().addComponents(
new ButtonBuilder()
.setCustomId("CheckValidated")
.setEmoji("✅")
.setLabel("Oui")
.setStyle(ButtonStyle.Success)
.setDisabled(true),
new ButtonBuilder()
.setCustomId("CheckDenied")
.setEmoji("❌")
.setLabel("Non")
.setStyle(ButtonStyle.Danger)
.setDisabled(true)
);
interaction.message.edit({ content: null, embeds: [AntiFail], components: [TicketActions] })
But...
(I am writing the end of my message)
When i have an other embed, with buttons too.
If i want to delete the buttons and change the embed (edit the message...) it doesn't work...
FIRST CODE
const { embed } = require("./Embed_etiquetage");
async function show_etiquetage(interaction, clientID)
{
await interaction.message.edit({ embeds: [embed], ephemeral: true})
}
module.exports = {
show_etiquetage
};
SECOND CODE
const { EmbedBuilder } = require("discord.js");
const embed = new EmbedBuilder()
.setTitle("Menu")
.setColor("#ffaf2e")
.setTimestamp()
.addFields(
{
name: "**blaliqzgdoqzo:**",
value: "blaliqzgdoqzo"
inline: false
},
)
module.exports = {
embed
}
That's not clear :/ Hmmm
I have this, when i click on red button i want the message completly change in an embed (second code)
For that I call the first code
Question: why not use interaction.update instead of interaction.message.edit?
Because the latter won‘t work for ephemeral messages like the one you show here
AH ! 😦
But wow it really exists 😦
Sorry to bother you all the time lol
There is no way to edit ephemeral messages?
Oh update works with ephemeral 😂
I just try it ^^, thanks !
I have another question if you're still here 🙂
In my message I have several ActionRowBuilder(), is it possible that when I update, I keep only one of my ActionRowBuilder()?
Sure.
Okay let's find how :p
Pass components: [thatRow] in your .update call
await interaction.update({ content: null, embeds: [embed_menu], components: [interaction.components[0]], ephemeral: true})
Was there content before you want to remove? Else you won‘t need the content:null at all
Yes there is
interaction.message.components[0]
Thx ❤️
Me again, would it be possible to target ONLY channel name changes here?
Because currently it also triggers me to stop actions on other things like bulkdelete() and I don't want it to do that
route: '/channels/:id/messages/bulk-delete'
rejectOnRateLimit also accepts a function instead of a string array. If you pass a function it‘ll get called with the full RateLimitData (including route and method) and will reject if that function returns something truthy, queue the request for any falsey return value
So you’d only want to return true if .method equals PATCH and .route equals /channels/:id
Hmm 🤔
function ratelimit_handler() {
if (req.method === 'PATCH ' && req.route === '/channels/:id') {
return true;
} else {
return false;
}
}
const client = new Client({
intents: [Guilds, GuildMembers, GuildMessages, DirectMessages],
partials: [User, Message, GuildMember, ThreadMember, Channel],
rest: {
rejectOnRateLimit: ratelimit_handler()
}
});
@blissful zenith
What about the arg?
Pass the function, not the return value of calling the function. So no () when passing it to rejectOnRateLimit. But it gets one arg, so when defining the function it should have a parameter, that you apparently want to name req
Hmm okay, something like that
function ratelimit_handler(req) {
if (req.method === 'PATCH ' && req.route === '/channels/:id') {
return true;
} else {
return false;
}
}
const client = new Client({
intents: [Guilds, GuildMembers, GuildMessages, DirectMessages],
partials: [User, Message, GuildMember, ThreadMember, Channel],
rest: {
rejectOnRateLimit: ratelimit_handler
}
});
Thank you again, I don't know what I would do without you 🥲
Any error when i execute that (rate limit is reached) 
try {
channel.setName("🚫 dev-only")
} catch (error) {
console.log(error)
}
& after 10 mins
It seems that it doesn't work 😦
Fix, i juste wrote ```js
'PATCH ' instead of 'PATCH'
Doesn't work :/
name: 'channelCreate',
/**
*
* @param {Channel} channel
* @param {Client} client
*/
async execute (channel, client) {
const { guild } = channel;
//ID OF THE PRINCIPAL SRV (string)
const principal_guild = client.config.guild.principal;
//ID OF THE LOG SRV (string)
const log_guild = client.config.guild.logs;
//DETECT THE CREATION OF A CHANNEL IN THE MAIN SRV
if (channel.type === ChannelType.GuildText && guild.id === principal_guild){
// zone where i crash
await client.guilds.cache.get(log_guild).channels.find(c => c.name === channel.parent.name &&
c.type === ChannelType.GuildCategory).then(async (category_find) => {
console.log("CATEGORY FOUND");
category_find.channels.create({
name: channel.name,
type: ChannelType.GuildText,
position: channel.position,
topic: channel.topic
})
})
}
My goal is to create a parallel server to a first server.
Here I am trying to create a channel in the side server when a channel is created in the main server
@blissful zenith
I find this solution, don't know if it's the best but it works
const { guild } = channel;
const principal_guild = client.config.guild.principal;
const log_guild = client.guilds.cache.get(log_guild);
// if (channel.type === ChannelType.GuildCategory && guild.id === principal_guild){
// var name_category = channel.name;
// var position_category = channel.position;
//
// await log_guild.channels.create({
// name: name_category,
// type: ChannelType.GuildCategory,
// position: position_category
// })
// }
if (channel.type === ChannelType.GuildText && guild.id === principal_guild){
const categ = log_guild.channels.cache.find(c => c.name === channel.parent.name && c.type === ChannelType.GuildCategory)
log_guild.channels.create({
name: channel.name,
type: ChannelType.GuildText,
position: channel.position,
topic: channel.topic,
parent: categ.id
})
}