Exemplo n.º 1
0
async def on_ready():
    bot.guild = bot.guilds[0]

    bot.command_log_channel = \
        get_channel(bot.guild.channels, config["command_log_channel"]) if config["command_log_channel"] else None
    bot.moderation_log_channel = \
        get_channel(bot.guild.channels, config["moderation_log_channel"]) if config["moderation_log_channel"] else bot.command_log_channel
    bot.event_log_channel = \
        get_channel(bot.guild.channels, config["event_log_channel"]) if config["event_log_channel"] else bot.command_log_channel
    print("Bot ready, loading extensions")
    # Create Databases directory if it's missing since sqlite3 won't create directories
    if not os.path.isdir("Databases/"):
        os.makedirs("Databases/")

    # Extension loading code adapted from appu1232/discord-selfbot
    for entry in os.listdir("extensions"):
        if os.path.isdir("extensions/{}".format(entry)):
            for extension in os.listdir("extensions/{}".format(entry)):
                if extension.endswith('.py'):
                    try:
                        bot.load_extension("extensions.{}.{}".format(
                            entry, extension[:-3]))
                    except Exception as e:
                        print('Failed to load extension {}/{}\n{}: {}'.format(
                            entry, extension,
                            type(e).__name__, e))
        elif os.path.isfile(
                "extensions/{}".format(entry)) and entry.endswith('.py'):
            try:
                bot.load_extension("extensions.{}".format(entry[:-3]))
            except Exception as e:
                print('Failed to load extension {}\n{}: {}'.format(
                    entry,
                    type(e).__name__, e))

    print("Bot ready!")

    # Check if a channel name is passed via argv to output restart message on
    if len(sys.argv) > 1:
        try:
            channel = bot.get_channel(int(sys.argv[1]))
            await channel.send("Bot has restarted")
        except:
            pass
Exemplo n.º 2
0
 async def membercount(self, ctx, channel=""):
     """Returns member count in the specified channel, or the server if not specified"""
     if channel:
         channel = get_channel(ctx.guild.channels, channel)
         if not channel:
             await ctx.send("That channel doesn't exist!")
         elif not ctx.author.permissions_in(channel).read_messages:
             await ctx.send("You cannot view the member count in this channel")
         else:
             await ctx.send("There are {} members in {}".format(len(channel.members), channel.name))
     else:
         await ctx.send("{} currently has {} members".format(ctx.guild.name, ctx.guild.member_count))