Discord4J – 仅在特定频道中使用斜杠命令

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

Discord4J - Slash Command only in a specific channel

问题

我目前正在使用Java中的Discord4J库开发一个Discord机器人,并且我想创建一个仅在特定频道可用且不在其他频道建议的斜杠命令。

目前,我已经成功实现了斜杠命令,并且它在机器人活动的所有频道中都显示出来。然而,我希望该命令仅在特定频道中建议,并且不会出现在其他频道中。

我已经像其他命令一样实现了该命令,使用了以下代码。然而,它在每个频道中都显示出来,而不仅仅是在特定频道中,这与预期不符:

List<CommandData> commandData = new ArrayList<>();

commandData.add(Commands.slash("poll", "创建一个投票")
        .setDefaultPermissions(DefaultMemberPermissions.enabledFor(Permission.ADMINISTRATOR))
        .setGuildOnly(true));

非常感谢您的帮助!

英文:

I am currently working on a Discord bot using the Discord4J library in Java, and I would like to create a slash command that is only available in a specific channel and is not suggested in other channels.

Currently, I have successfully implemented the slash command and it shows up in all channels where the bot is active. However, I would like the command to be suggested only in a specific channel and not appear in other channels.

I have implemented the command as any other already with the following code. However, there it is displayed in every channel and not only in a specific one as expected:

`List<CommandData> commandData = new ArrayList<>();

    commandData.add(Commands.slash(&quot;poll&quot;, &quot;Erstelle eine Umfrage&quot;)
            .setDefaultPermissions(DefaultMemberPermissions.enabledFor(Permission.ADMINISTRATOR))
            .setGuildOnly(true));`

Thanks in advance for your help!

答案1

得分: 1

你可以在服务器设置中禁用特定频道的命令。
不幸的是,你无法通过API进行编辑(这不是Discord4J的问题,而是Discord的限制)。

  1. 转到“集成”设置

  2. 选择要编辑的机器人

  3. 选择要禁用的命令

  4. 点击“添加频道”

  5. 选择要禁用的频道,然后有效地禁用该命令

英文:

You can disable the command from the server settings for certain channels.
Unfortunately, you can't edit this via the API (not a Discord4J issue, it's a Discord restriction).

  1. Go to the "integrations" settings

Discord4J – 仅在特定频道中使用斜杠命令

  1. Select the bot you want to edit

Discord4J – 仅在特定频道中使用斜杠命令

  1. Select the command you want to disable

Discord4J – 仅在特定频道中使用斜杠命令

  1. Click on "add channel"

Discord4J – 仅在特定频道中使用斜杠命令

  1. Select the channel(s) you want to disable, then effectively disable the command

Discord4J – 仅在特定频道中使用斜杠命令

huangapple
  • 本文由 发表于 2023年7月17日 15:15:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/76702215.html
匿名

发表评论

匿名网友

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

确定