“setTopic() Rate Limit problems” 可以翻译为 “setTopic() 速率限制问题”。

huangapple go评论69阅读模式
英文:

setTopic() Rate Limit problems

问题

我在尝试使用.setTopic()更改TextChannel主题时遇到速率限制错误。这很奇怪,因为我在这里没有做太多事情...
只有在添加大延迟,如10秒(对于我的项目来说无法做到)时才有效,即使使用看似很长的延迟,如5秒,我仍然会收到错误。
saveEquationToMongorandomEquation这两个函数都没有引起问题的任何操作。

以下是错误消息:

[JDA RateLimit-Worker 2] WARN RateLimiter - 在路由PATCH/channels/{channel_id}中遇到了429,桶为6e836da6cef38ba2f3dfd8568a4e9631:channel_id=1111635288435994706 Retry-After: 512000 ms

以下是我的代码:

 @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();

    }
}
英文:

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();

        }
    ```




</details>


# 答案1
**得分**: 2

你每 10 分钟只能更改频道主题两次。你所观察到的是 *警告* 而不是 *错误*,如日志级别 WARN 所示。

此外,对于斜杠命令交互,你应该使用 `event.reply(...)` 而不是向频道发送消息。

<details>
<summary>英文:</summary>

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.

</details>



huangapple
  • 本文由 发表于 2023年5月30日 00:33:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/76358960.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定