当前位置: 首页>>代码示例>>Java>>正文


Java JDA.getSelfUser方法代码示例

本文整理汇总了Java中net.dv8tion.jda.core.JDA.getSelfUser方法的典型用法代码示例。如果您正苦于以下问题:Java JDA.getSelfUser方法的具体用法?Java JDA.getSelfUser怎么用?Java JDA.getSelfUser使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.dv8tion.jda.core.JDA的用法示例。


在下文中一共展示了JDA.getSelfUser方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setNickname

import net.dv8tion.jda.core.JDA; //导入方法依赖的package包/类
public static final boolean setNickname(String nickname) {
    if (nickname == null || nickname.isEmpty()) {
        return false;
    }
    Config.CONFIG.setBotNickname(nickname);
    try {
        final JDA jda = getJDA();
        if (jda != null) {
            final SelfUser user = jda.getSelfUser();
            if (user != null) {
                if (!nickname.equals(user.getName())) {
                    final AccountManager manager = user.getManager();
                    if (manager != null) {
                        manager.setName(nickname).queue();
                        System.out.println("Changed nickname to \"" + nickname + "\".");
                        return true;
                    } else {
                        System.err.println("Failed to change nickname to \"" + nickname + "\": AccountManager is null!");
                    }
                } else {
                    //System.err.println("Failed to change nickname to \"" + nickname + "\": Nickname is already set!");
                }
            } else {
                System.err.println("Failed to change nickname to \"" + nickname + "\": SelfUser is null!");
            }
        } else {
            System.err.println("Failed to change nickname to \"" + nickname + "\": JDA is null!");
        }
        return false;
    } catch (Exception ex) {
        System.err.println("Failed to change nickname to \"" + nickname + "\"");
        //ex.printStackTrace();
        return false;
    }
}
 
开发者ID:Panzer1119,项目名称:Supreme-Bot,代码行数:36,代码来源:Standard.java

示例2: handleSettingsDisplay

import net.dv8tion.jda.core.JDA; //导入方法依赖的package包/类
private void handleSettingsDisplay(DiscordBot bot, GuildMessageReceivedEvent event) {
    JDA shard = event.getJDA();
    TextChannel channel = event.getChannel();
    Message message = event.getMessage();
    SelfUser selfUser = shard.getSelfUser();
    String output = getSettingsString(bot, event);

    EmbedBuilder embed = new EmbedBuilder();
    embed.setAuthor("Safety Jim", null, selfUser.getAvatarUrl());
    embed.addField("Guild Settings", output, false);
    embed.setColor(new Color(0x4286F4));

    DiscordUtils.successReact(bot, message);
    DiscordUtils.sendMessage(channel, embed.build());
}
 
开发者ID:Samoxive,项目名称:SafetyJim,代码行数:16,代码来源:Settings.java

示例3: run

import net.dv8tion.jda.core.JDA; //导入方法依赖的package包/类
@Override
public boolean run(DiscordBot bot, GuildMessageReceivedEvent event, String args) {
    DSLContext database = bot.getDatabase();
    Config config = bot.getConfig();
    JDA currentShard = event.getJDA();
    List<JDA> shards = bot.getShards().stream().map((shard) -> shard.getShard()).collect(Collectors.toList());
    Guild guild = event.getGuild();
    SelfUser selfUser = currentShard.getSelfUser();
    Message message = event.getMessage();
    TextChannel channel = event.getChannel();

    int shardCount = shards.size();
    int shardId = DiscordUtils.getShardIdFromGuildId(guild.getIdLong(), shardCount);
    String shardString = DiscordUtils.getShardString(shardId, shardCount);

    String uptimeString = prettyTime.format(bot.getStartTime());

    long guildCount = bot.getGuildCount();
    int channelCount = shards.stream()
                          .mapToInt((shard) -> shard.getTextChannels().size())
                          .sum();
    int userCount = shards.stream()
                          .mapToInt((shard) -> shard.getUsers().size())
                          .sum();
    long pingShard = currentShard.getPing();
    long pingAverage = shards.stream()
                             .mapToLong((shard) -> shard.getPing())
                             .sum() / shardCount;

    Runtime runtime = Runtime.getRuntime();
    long ramTotal = runtime.totalMemory() / (1024 * 1024);
    long ramUsed = ramTotal - (runtime.freeMemory() / (1024 * 1024));

    BanlistRecord lastBanRecord = database.selectFrom(Tables.BANLIST)
                                          .where(Tables.BANLIST.GUILDID.eq(guild.getId()))
                                          .orderBy(Tables.BANLIST.BANTIME.desc())
                                          .fetchAny();

    String daysSince = "\u221E"; // Infinity symbol

    if (lastBanRecord != null) {
        Date now = new Date();
        long dayCount = ((now.getTime() / 1000) - lastBanRecord.getBantime()) / (60 * 60 * 24);
        daysSince = Long.toString(dayCount);
    }

    EmbedBuilder embed = new EmbedBuilder();
    embed.setAuthor(String.format("Safety Jim - v%s - Shard %s", config.version, shardString), null, selfUser.getAvatarUrl());
    embed.setDescription("Lifting the :hammer: since " + uptimeString);
    embed.addField("Server Count", Long.toString(guildCount), true);
    embed.addField("User Count", Integer.toString(userCount), true);
    embed.addField("Channel Count", Integer.toString(channelCount), true);
    embed.addField("Websocket Ping", String.format("Shard %s: %dms\nAverage: %dms", shardString, pingShard, pingAverage), true);
    embed.addField("RAM usage", String.format("%dMB / %dMB", ramUsed, ramTotal), true);
    embed.addField("Links", String.format("[Support](%s) | [Github](%s) | [Invite](%s)", supportServer, githubLink, botInviteLink), true);
    embed.setFooter("Made by Safety Jim team. | Days since last incident: " + daysSince, null);
    embed.setColor(new Color(0x4286F4));

    DiscordUtils.successReact(bot, message);
    DiscordUtils.sendMessage(channel, embed.build());

    return false;
}
 
开发者ID:Samoxive,项目名称:SafetyJim,代码行数:64,代码来源:Info.java


注:本文中的net.dv8tion.jda.core.JDA.getSelfUser方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。