简体   繁体   English

如何使用 Discord API 指定父类别?

[英]How do you specify a parent category using the Discord API?

I am trying to create a ticket discord bot that generates a text channel and places it in a category.我正在尝试创建一个票证 discord 机器人,它生成一个文本通道并将其放在一个类别中。 Here is what I have currently:这是我目前拥有的:

import net.dv8tion.jda.api.entities.Category;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import net.dv8tion.jda.internal.entities.TextChannelImpl;

public class Commands extends ListenerAdapter {
    public void onMessageReceived(MessageReceivedEvent event) {
        if (event.getMessage().getContentRaw().equals(".new")) {
            event.getChannel().sendMessage("Created new Ticket");
            event.getGuild().createTextChannel("Ticket", "777209975935467541");
             
        }
    }
}

It keeps giving telling me the category ("777209975935467541") can not be a String or Long.它一直告诉我类别(“777209975935467541”)不能是字符串或长。 If anyone can help me that would be great!如果有人可以帮助我,那就太好了!

You can use category.createTextChannel("ticket").queue() .您可以使用category.createTextChannel("ticket").queue()

Example:例子:

MessageChannel channel = event.getChannel();
Category category = event.getGuild().getCategoryById(777209975935467541L);
if (category == null) {
  channel.sendMessage("Cannot create a ticket, because i didn't use the right channel id for the category!").queue();
  return;
}

category.createTextChannel("ticket")
        .flatMap(ticket -> channel.sendMessageFormat("Created ticket at %s", ticket))
        .queue();

See Category#createTextChannel .请参阅类别#createTextChannel

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从父目录进行编译时,如何在清单文件中指定主类? - How do you specify a main class in a manifest file when compiling from the parent directory? 如何使用Java Discord API删除文本通道? - How do I delete a text channel using Java Discord API? 你如何在 Java 中指定字节文字? - How do you specify a byte literal in Java? 在Spring中,如何指定BindingResult实现 - In Spring, how do you specify the BindingResult implementation 如何使用spring指定可以动态更改的数据源 - How do you specify a datasource with spring that you can change dynamically 您如何指定要使工具栏中的元素居中? - How do you specify that you want your elements in a ToolBar to be centered? 使用groovy-all jar运行Groovy脚本时,如何指定类路径? - When running Groovy scripts using the groovy-all jar, how do you specify a classpath? Blackberry-如何在不使用JDE或Eclipse插件的情况下为应用程序主方法指定参数? - Blackberry - how do you specify argument(s) to application main method without using JDE or Eclipse plugin? 如何使用Android Studio的App Inventor Java Bridge库指定图像路径? - How do you specify image path using App Inventor Java Bridge library for Android Studio? 如何使用单个命令在UNIX文件系统中提取JAR并使用JAR命令指定其目标目录? - How do you extract a JAR in a UNIX filesystem with a single command and specify its target directory using the JAR command?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM