如何使用discordapi指定父类别?

siotufzp  于 2021-07-06  发布在  Java
关注(0)|答案(1)|浏览(400)

我正在尝试创建一个ticketdiscord机器人,它生成一个文本频道并将其放置在一个类别中。以下是我目前的情况:

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

        }
    }
}

它一直告诉我类别(“777209975935467541”)不能是字符串或长字符串。太好了!

5sxhfpxr

5sxhfpxr1#

你可以用 category.createTextChannel("ticket").queue() .
例子:

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

请参阅类别#createtextchannel。

相关问题