javadiscordrate-limitingdiscord-jda

setTopic() Rate Limit problems


I am getting a rate limit error when trying to change the topic of a TextChannel via .setTopic(). It is weird becouse i am not really doing much here... It only works when adding a huge delay, like 10 seconds ( which i cannot do for my project ) even with seemingly high delays like 5 seconds i get the error. None of the funcitons (saveEquationToMongo and randomEquation ) do anything that could cause problems.

Here is the ERROR:

[JDA RateLimit-Worker 2] WARN RateLimiter - Encountered 429 on route PATCH/channels/{channel_id} with bucket 6e836da6cef38ba2f3dfd8568a4e9631:channel_id=1111635288435994706 Retry-After: 512000 ms

Here is my code:

 @Override
    public void onSlashCommandInteraction(@NotNull SlashCommandInteractionEvent event) {

        if(event.getInteraction().getName().equals("equation")){

            Equation equation = null;
            try {
                equation = randomEquation();
            } catch (Exception e) {
                e.printStackTrace();
            }

            int answer = equation.getAnswer();
            System.out.println(answer);
            String equationString = equation.getEquation();

            MessageEmbed embed = new EmbedBuilder()
                    .setTitle("Solve this equation:")
                    .addField(equationString, "Be the first one to do it! \n Just send in the answers to this channel.", false)
                    .setColor(Color.YELLOW)
                    .build();
            event.getChannel().asTextChannel().sendMessageEmbeds(embed).queue(message -> {
                String messageId = message.getId();
                String channelId = message.getChannel().getId();
                String channelTopic = event.getChannel().asTextChannel().getTopic();

                saveEquationToMongo(equationString, answer, messageId, channelId, channelTopic);

                TextChannel channel = event.getChannel().asTextChannel();
                channel.getManager().setTopic("Currently playing the Equations Game...").queueAfter(500, TimeUnit.MILLISECONDS);

            });


           // event.reply(equationString  + " = " + answer).queue();

        }
    ```



Solution

  • You can only change the channel topic twice every 10 minutes. What you are observing is a warning not an error, as indicated by the log level WARN.

    Additionally, for a slash command interaction, you are supposed to use event.reply(...) instead of sending a message to the channel.