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

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

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

以下是我的代码:

  1. @Override
  2. public void onSlashCommandInteraction(@NotNull SlashCommandInteractionEvent event) {
  3. if(event.getInteraction().getName().equals("equation")){
  4. Equation equation = null;
  5. try {
  6. equation = randomEquation();
  7. } catch (Exception e) {
  8. e.printStackTrace();
  9. }
  10. int answer = equation.getAnswer();
  11. System.out.println(answer);
  12. String equationString = equation.getEquation();
  13. MessageEmbed embed = new EmbedBuilder()
  14. .setTitle("Solve this equation:")
  15. .addField(equationString, "Be the first one to do it! \n Just send in the answers to this channel.", false)
  16. .setColor(Color.YELLOW)
  17. .build();
  18. event.getChannel().asTextChannel().sendMessageEmbeds(embed).queue(message -> {
  19. String messageId = message.getId();
  20. String channelId = message.getChannel().getId();
  21. String channelTopic = event.getChannel().asTextChannel().getTopic();
  22. saveEquationToMongo(equationString, answer, messageId, channelId, channelTopic);
  23. TextChannel channel = event.getChannel().asTextChannel();
  24. channel.getManager().setTopic("Currently playing the Equations Game...").queueAfter(500, TimeUnit.MILLISECONDS);
  25. });
  26. // event.reply(equationString + " = " + answer).queue();
  27. }
  28. }
英文:

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:

  1. @Override
  2. public void onSlashCommandInteraction(@NotNull SlashCommandInteractionEvent event) {
  3. if(event.getInteraction().getName().equals("equation")){
  4. Equation equation = null;
  5. try {
  6. equation = randomEquation();
  7. } catch (Exception e) {
  8. e.printStackTrace();
  9. }
  10. int answer = equation.getAnswer();
  11. System.out.println(answer);
  12. String equationString = equation.getEquation();
  13. MessageEmbed embed = new EmbedBuilder()
  14. .setTitle("Solve this equation:")
  15. .addField(equationString, "Be the first one to do it! \n Just send in the answers to this channel.", false)
  16. .setColor(Color.YELLOW)
  17. .build();
  18. event.getChannel().asTextChannel().sendMessageEmbeds(embed).queue(message -> {
  19. String messageId = message.getId();
  20. String channelId = message.getChannel().getId();
  21. String channelTopic = event.getChannel().asTextChannel().getTopic();
  22. saveEquationToMongo(equationString, answer, messageId, channelId, channelTopic);
  23. TextChannel channel = event.getChannel().asTextChannel();
  24. channel.getManager().setTopic("Currently playing the Equations Game...").queueAfter(500, TimeUnit.MILLISECONDS);
  25. });
  26. // event.reply(equationString + " = " + answer).queue();
  27. }
  28. ```
  29. </details>
  30. # 答案1
  31. **得分**: 2
  32. 你每 10 分钟只能更改频道主题两次。你所观察到的是 *警告* 而不是 *错误*,如日志级别 WARN 所示。
  33. 此外,对于斜杠命令交互,你应该使用 `event.reply(...)` 而不是向频道发送消息。
  34. <details>
  35. <summary>英文:</summary>
  36. 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.
  37. Additionally, for a slash command interaction, you are supposed to use `event.reply(...)` instead of sending a message to the channel.
  38. </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:

确定