本文整理汇总了Java中net.dv8tion.jda.core.JDA.getGuildById方法的典型用法代码示例。如果您正苦于以下问题:Java JDA.getGuildById方法的具体用法?Java JDA.getGuildById怎么用?Java JDA.getGuildById使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.dv8tion.jda.core.JDA
的用法示例。
在下文中一共展示了JDA.getGuildById方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: start
import net.dv8tion.jda.core.JDA; //导入方法依赖的package包/类
@Override
public void start() {
getBot().getCommandHandler().addCommand("invite", new InviteCommand(getBot()), "General Commands");
log.info("Command !invite loaded!");
getBot().getCommandHandler().addCommand("help", new HelpCommand(getBot()), "General Commands");
log.info("Command !help loaded!");
getBot().getCommandHandler().addCommand("info", new InfoCommand(getBot()), "General Commands");
//We find our main guild
Guild guild = null;
for (JDA jda : getBot().getJDA()) {
Guild guildEntry = jda.getGuildById("330748360673722381");
if (guildEntry != null) {
guild = guildEntry;
}
}
listener = new MessageListener(guild);
getBot().getJDA().forEach(jda -> jda.addEventListener(listener));
}
示例2: getDtoForView
import net.dv8tion.jda.core.JDA; //导入方法依赖的package包/类
public WebHookDto getDtoForView(long guildId, WebHook webHook) {
WebHookDto hookDto = mapper.getWebHookDto(webHook);
if (discordService.isConnected()) {
JDA jda = discordService.getJda();
Guild guild = jda.getGuildById(guildId);
if (guild != null && guild.getSelfMember().hasPermission(Permission.MANAGE_WEBHOOKS)) {
hookDto.setAvailable(true);
Webhook webhook = webHookService.getWebHook(guild, webHook);
if (webhook != null) {
hookDto.setChannelId(webhook.getChannel().getIdLong());
} else {
hookDto.setEnabled(false);
}
}
}
return hookDto;
}
示例3: getGuildById
import net.dv8tion.jda.core.JDA; //导入方法依赖的package包/类
public Guild getGuildById(long id)
{
for(JDA shard: shards)
{
Guild g = shard.getGuildById(id);
if(g!=null)
return g;
}
return null;
}
示例4: spawnRole
import net.dv8tion.jda.core.JDA; //导入方法依赖的package包/类
/**
* generates a temporary RSVP group role for dynamic user mentioning
* the role will last for some time before being removed
* @param group the rsvp group
* @return the newly created Role
*/
public Role spawnRole(String group)
{
List<String> members = this.rsvpMembers.get(group);
JDA jda = Main.getShardManager().getJDA(this.guildId);
Guild guild = jda.getGuildById(guildId);
// create the event RSVP role
Role role = guild.getController().createRole()
.setName(group)
.setMentionable(true)
.setColor(Color.ORANGE)
//.setColor((int) (Math.random()*Integer.MAX_VALUE+1)) // use a random color
.complete();
// add all RSVP'ed members to the role
members.forEach(memberId ->
{
if (memberId.matches("\\d+"))
{
Member member = guild.getMemberById(memberId);
guild.getController().addSingleRoleToMember(member, role)
.reason("dynamic RSVP role for event announcement").complete();
}
});
// automatically remove the role after 5 minutes
role.delete().queueAfter(60*5, TimeUnit.SECONDS);
return role;
}
示例5: get
import net.dv8tion.jda.core.JDA; //导入方法依赖的package包/类
public static GuildPlayer get(JDA jda, String k) {
GuildPlayer player = REGISTRY.get(k);
if (player == null) {
player = new GuildPlayer(jda, jda.getGuildById(k));
REGISTRY.put(k, player);
}
return player;
}
示例6: getGuildById
import net.dv8tion.jda.core.JDA; //导入方法依赖的package包/类
public static Guild getGuildById(String id) {
for (JDA jda : Bot.shards) {
Guild guild = jda.getGuildById(id);
if (guild != null) return guild;
}
return null;
}
示例7: getJDA
import net.dv8tion.jda.core.JDA; //导入方法依赖的package包/类
@Override
public JDA getJDA(Guild guild) {
for (JDA jda : jdaList) {
if (jda.getGuildById(guild.getId()) != null) {
return jda;
}
}
return null;
}
示例8: getGuildById
import net.dv8tion.jda.core.JDA; //导入方法依赖的package包/类
/**
* Get a guild from an ID from all shards
* @param guildId Guild ID
* @return Guild if found, null if not
*/
public Guild getGuildById(long guildId) {
for (JDA j : jdaClients) {
Guild g;
if ((g = j.getGuildById(guildId)) != null) {
return g;
}
}
return null;
}
示例9: execute
import net.dv8tion.jda.core.JDA; //导入方法依赖的package包/类
@Override
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
JDA jda = discordService.getJda();
if (jda == null || !JDA.Status.CONNECTED.equals(jda.getStatus())) {
throw new RuntimeException("Could not send reminder, not connected!");
}
JobDataMap data = jobExecutionContext.getJobDetail().getJobDataMap();
String userId = data.getString(ATTR_USER_ID);
String guildId = data.getString(ATTR_GUILD_ID);
String channelId = data.getString(ATTR_CHANNEL_ID);
String messageRaw = data.getString(ATTR_MESSAGE);
MessageChannel channel = null;
User user = jda.getUserById(userId);
StringBuilder message = new StringBuilder();
if (guildId != null) {
Guild guild = jda.getGuildById(guildId);
if (guild != null) {
channel = guild.getTextChannelById(channelId);
if (user != null && guild.isMember(user)) {
message.append(user.getAsMention()).append(" ");
}
}
} else {
channel = jda.getPrivateChannelById(channelId);
}
if (channel == null && user != null) {
channel = user.openPrivateChannel().complete();
}
if (channel != null) {
message.append(messageRaw);
channel.sendMessage(message.toString()).queue();
}
}
示例10: delete
import net.dv8tion.jda.core.JDA; //导入方法依赖的package包/类
public boolean delete(long guildId, WebHook webHook) {
if (discordService.isConnected()) {
JDA jda = discordService.getJda();
Guild guild = jda.getGuildById(guildId);
if (guild != null && guild.getSelfMember().hasPermission(Permission.MANAGE_WEBHOOKS)) {
Webhook webhook = getWebHook(guild, webHook);
if (webhook != null) {
webhook.delete().queue();
return true;
}
}
}
return false;
}
示例11: action
import net.dv8tion.jda.core.JDA; //导入方法依赖的package包/类
@Override
public void action(Invoker invoker, ArgumentList arguments, MessageEvent event) {
final JDA jda = Standard.getJDA();
if (jda == null) {
event.sendMessage(Standard.STANDARD_MESSAGE_DELETING_DELAY, Standard.getMessageEmbed(Color.RED, "%s Sorry %s, the Bot has no connection!", Emoji.WARNING, event.getAuthor().getAsMention()).build());
return;
}
final boolean message = arguments.isConsumed(Standard.ARGUMENT_MESSAGE, ArgumentConsumeType.CONSUME_FIRST_IGNORE_CASE);
String guild_id = null;
final int server = arguments.consume(Standard.ARGUMENT_SERVER, ArgumentConsumeType.CONSUME_FIRST_IGNORE_CASE, true);
if (server != -1) {
guild_id = arguments.consume(server);
}
if (message) {
final String message_id = arguments.consumeFirst();
final String channel_id = arguments.consumeFirst();
Guild guild = null;
RestAction<Message> msg = null;
if (guild_id != null) {
event.sendMessageFormat("message_id: %s, channel_id: %s, guild_id: %s", message_id, channel_id, guild_id);
guild = jda.getGuildById(guild_id);
} else {
event.sendMessageFormat("message_id: %s, channel_id: %s", message_id, channel_id);
guild = jda.getGuildById(event.getGuild().getId());
}
System.out.println("FOUND GUILD: " + guild);
msg = event.getMessageChannel().getMessageById(message_id);
if (msg != null) {
if (guild != null) {
final TextChannel channel = guild.getTextChannelById(channel_id);
if (channel != null) {
channel.sendMessage(msg.complete()).queue();
} else {
event.sendMessage(Standard.STANDARD_MESSAGE_DELETING_DELAY, Standard.getMessageEmbed(Color.RED, "%s Sorry %s, you'r channel \"%s\" wasn't found!", Emoji.WARNING, event.getAuthor().getAsMention(), channel_id).build());
}
} else {
event.sendMessage(Standard.STANDARD_MESSAGE_DELETING_DELAY, Standard.getMessageEmbed(Color.RED, "%s Sorry %s, you'r server \"%s\" wasn't found!", Emoji.WARNING, event.getAuthor().getAsMention(), (guild_id != null ? guild_id : event.getGuild().getId())).build());
}
} else {
event.sendMessage(Standard.STANDARD_MESSAGE_DELETING_DELAY, Standard.getMessageEmbed(Color.RED, "%s Sorry %s, you'r message \"%s\" wasn't found!", Emoji.WARNING, event.getAuthor().getAsMention(), message_id).build());
}
} else {
event.sendMessage(Standard.STANDARD_MESSAGE_DELETING_DELAY, Standard.getMessageEmbed(Color.RED, "%s Sorry %s, this operation isn't supported yet!", Emoji.WARNING, event.getAuthor().getAsMention()).build());
}
}
示例12: closePortal
import net.dv8tion.jda.core.JDA; //导入方法依赖的package包/类
private void closePortal(CommandManager.ParsedCommandInvocation parsedCommandInvocation) {
JDA jda = parsedCommandInvocation.getMessage().getJDA();
Guild messageGuild = parsedCommandInvocation.getMessage().getGuild();
TextChannel messageChannel = parsedCommandInvocation.getMessage().getTextChannel();
//Check if portal exists
String oldGuildPortalEntry = RubiconBot.getMySQL().getGuildValue(messageGuild, "portal");
if (oldGuildPortalEntry.equals("closed")) {
messageChannel.sendMessage(EmbedUtil.error("Portal error!", "Portal is already closed").build()).queue();
return;
}
if (oldGuildPortalEntry.equals("waiting")) {
RubiconBot.getMySQL().updateGuildValue(messageGuild, "portal", "closed");
messageChannel.sendMessage(EmbedUtil.success("Portal", "Successful closed portal request.").build()).queue();
return;
}
Guild partnerGuild = jda.getGuildById(RubiconBot.getMySQL().getPortalValue(messageGuild, "partnerid"));
//Close Channels
TextChannel channelOne = null;
TextChannel channelTwo = null;
try {
channelOne = jda.getTextChannelById(RubiconBot.getMySQL().getPortalValue(messageGuild, "channelid"));
channelTwo = jda.getTextChannelById(RubiconBot.getMySQL().getPortalValue(partnerGuild, "channelid"));
} catch (NullPointerException ignored) {
//Channels doesn't exist
}
if (channelOne != null)
channelOne.getManager().setName(closedChannelName).queue();
if (channelTwo != null)
channelTwo.getManager().setName(closedChannelName).queue();
//Close and delete DB Portal
RubiconBot.getMySQL().updateGuildValue(messageGuild, "portal", "closed");
RubiconBot.getMySQL().deletePortal(messageGuild);
RubiconBot.getMySQL().updateGuildValue(partnerGuild, "portal", "closed");
RubiconBot.getMySQL().deletePortal(partnerGuild);
EmbedBuilder portalClosedMessage = new EmbedBuilder();
portalClosedMessage.setAuthor("Portal closed!", null, jda.getSelfUser().getEffectiveAvatarUrl());
portalClosedMessage.setDescription("Portal was closed. Create a new one with `" + parsedCommandInvocation.getPrefix() + "portal create`");
portalClosedMessage.setColor(Colors.COLOR_ERROR);
channelOne.sendMessage(portalClosedMessage.build()).queue();
portalClosedMessage.setDescription("Portal was closed. Create a new one with `" + parsedCommandInvocation.getPrefix() + "portal create`");
channelTwo.sendMessage(portalClosedMessage.build()).queue();
channelOne.getManager().setTopic("Portal closed").queue();
channelTwo.getManager().setTopic("Portal closed").queue();
}
示例13: handle
import net.dv8tion.jda.core.JDA; //导入方法依赖的package包/类
@Override
public void handle(RoutingContext ctx, Server server, DiscordBot bot, DSLContext database) {
HttpServerRequest request = ctx.request();
HttpServerResponse response = ctx.response();
String guildId = request.getParam("guildId");
int shardId = DiscordUtils.getShardIdFromGuildId(Long.parseLong(guildId), bot.getConfig().jim.shard_count);
JDA shard = bot.getShards().get(shardId).getShard();
Guild guild = shard.getGuildById(guildId);
SettingsRecord record = database.selectFrom(Tables.SETTINGS)
.where(Tables.SETTINGS.GUILDID.eq(guildId))
.fetchAny();
if (record == null || guild == null) {
response.setStatusCode(404);
response.end();
return;
}
Gson gson = new GsonBuilder().serializeNulls().create();
List<PartialChannel> channels = guild.getTextChannels()
.stream()
.map((channel) -> new PartialChannel(channel.getId(), channel.getName()))
.collect(Collectors.toList());
List<PartialRole> roles = guild.getRoles()
.stream()
.map((role) -> new PartialRole(role.getId(), role.getName()))
.collect(Collectors.toList());
Channel modLogChannel = shard.getTextChannelById(record.getModlogchannelid());
PartialChannel modLogChannelPartial = new PartialChannel(modLogChannel.getId(), modLogChannel.getName());
Channel welcomeMessageChannel = shard.getTextChannelById(record.getWelcomemessagechannelid());
PartialChannel welcomeMessageChannelPartial = new PartialChannel(welcomeMessageChannel.getId(), welcomeMessageChannel.getName());
Role holdingRoomRole = null;
PartialRole holdingRoomRolePartial = null;
if (record.getHoldingroomroleid() != null) {
holdingRoomRole = shard.getRoleById(record.getHoldingroomroleid());
holdingRoomRolePartial = new PartialRole(holdingRoomRole.getId(), holdingRoomRole.getName());
}
GuildSettings settings = new GuildSettings(
guildId,
record.getModlog(),
modLogChannelPartial,
record.getHoldingroom(),
holdingRoomRolePartial,
record.getHoldingroomminutes(),
record.getInvitelinkremover(),
record.getWelcomemessage(),
record.getMessage(),
welcomeMessageChannelPartial,
record.getPrefix(),
record.getSilentcommands(),
record.getNospaceprefix(),
record.getStatistics(),
channels,
roles
);
String responseJson = gson.toJson(settings);
response.putHeader("Content-Type", "application/json");
response.end(responseJson);
}
示例14: onMessage
import net.dv8tion.jda.core.JDA; //导入方法依赖的package包/类
@Override
public void onMessage(String message) {
JSONObject json = new JSONObject(message);
if (!Objects.equals(json.getString("op"), "playerUpdate")) {
log.debug(message);
}
switch (json.getString("op")) {
case "sendWS":
JDAImpl jda = (JDAImpl) lavalink.getJda(json.getInt("shardId"));
jda.getClient().send(json.getString("message"));
break;
case "validationReq":
int sId = LavalinkUtil.getShardFromSnowflake(json.getString("guildId"), lavalink.getNumShards());
JDA jda2 = lavalink.getJda(sId);
String guildId = json.getString("guildId");
String channelId = json.optString("channelId");
if (channelId.equals("")) channelId = null;
JSONObject res = new JSONObject();
res.put("op", "validationRes");
res.put("guildId", guildId);
VoiceChannel vc = null;
if (channelId != null)
vc = jda2.getVoiceChannelById(channelId);
Guild guild = jda2.getGuildById(guildId);
if (guild == null && channelId == null) {
res.put("valid", false);
send(res.toString());
} else if (guild == null) {
res.put("valid", false);
res.put("channelId", channelId);
send(res.toString());
} else if (channelId != null) {
res.put("valid", vc != null
&& PermissionUtil.checkPermission(vc, guild.getSelfMember(),
Permission.VOICE_CONNECT, Permission.VOICE_SPEAK));
res.put("channelId", channelId);
send(res.toString());
} else {
res.put("valid", true);
send(res.toString());
}
break;
case "isConnectedReq":
JDAImpl jda3 = (JDAImpl) lavalink.getJda(json.getInt("shardId"));
JSONObject res2 = new JSONObject();
res2.put("op", "isConnectedRes");
res2.put("shardId", json.getInt("shardId"));
res2.put("connected", jda3.getClient().isConnected());
send(res2.toString());
break;
case "playerUpdate":
lavalink.getLink(json.getString("guildId"))
.getPlayer()
.provideState(json.getJSONObject("state"));
break;
case "stats":
stats = new RemoteStats(json);
break;
case "event":
try {
handleEvent(json);
} catch (IOException e) {
throw new RuntimeException(e);
}
break;
default:
log.warn("Unexpected operation: " + json.getString("op"));
break;
}
}