简体   繁体   中英

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. 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. If anyone can help me that would be great!

You can use 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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM