def __init__(self, client: commands.Bot): client.add_listener(self._on_reaction, "on_raw_reaction_add") client.add_listener(self._on_reaction_removed, "on_raw_reaction_remove") self.cleaner.start() self.client = client
async def initialize(bot: Bot, host, password, rest_port, ws_port): """ Initializes the websocket connection to the lavalink player. .. important:: This function must only be called AFTER the bot has received its "on_ready" event! Parameters ---------- bot host : str password : str rest_port : int ws_port : int """ global _loop _loop = bot.loop player_manager.user_id = bot.user.id player_manager.channel_finder_func = bot.get_channel register_event_listener(player_manager.handle_event) ws = websocket.WebSocket( _loop, dispatch, bot._connection._get_websocket, host, password, port=ws_port, user_id=player_manager.user_id, num_shards=bot.shard_count ) await ws.connect() rest_api.initialize(loop=_loop, host=host, port=rest_port, password=password) bot.add_listener(player_manager.on_socket_response)
def setup(bot: commands.Bot): """Load this cog.""" _check_folders() _check_files() cog = TriggerReact(bot) bot.add_listener(cog.trigger_reactions, "on_message") bot.add_cog(cog)
def setup(bot: commands.Bot): check_folders() check_files() n = StreamRole(bot) bot.add_listener(n.stream_listener, "on_member_update") bot.add_cog(n)
def setup(bot: commands.Bot): check_folders() check_files() n = CustomJoinLeave(bot) bot.add_listener(n.voice_state_update, "on_voice_state_update") bot.add_cog(n)
def __init__(self, bot: commands.Bot): self.bot = bot self.loop = bot.loop or asyncio.get_event_loop() self.nodes = {} bot.add_listener(self.update_handler, "on_socket_response")
def start(bot: commands.Bot): print('Adding listeners.') global __bot __bot = bot bot.add_listener(delete_messages_in_auto_delete_channels, 'on_message') bot.add_listener(anti_ghost, 'on_message') bot.add_listener(log.log_standard_action, 'on_command_completion') bot.add_listener(post_leave_message, 'on_member_remove') bot.add_listener(listen_for_stars, 'on_raw_reaction_add')
def __init__(self, bot: commands.Bot): self.bot = bot self.spotify_types = ["album", "playlist", "track"] if not hasattr(bot, "lavalink"): # This ensures the client isn"t overwritten during cog reloads. bot.lavalink = lavalink.Client(bot.user.id, loop=self.bot.loop) bot.lavalink.add_node(**self.bot.config.lavalink) bot.add_listener(bot.lavalink.voice_update_handler, "on_socket_response") bot.lavalink.add_event_hook(self.track_hook)
def __init__(self, bot: commands.Bot) -> None: bot.add_listener(self._handler, "on_socket_response") self.bot = bot self._loop = bot.loop self._sharded = isinstance(bot, commands.AutoShardedBot) self._shard_count = bot.shard_count if bot.shard_count is not None else 1 self._socket = None self._down = {} self._players = {} bot.aqualink = self
def __init__(self, bot: commands.Bot): self.bot = bot if not hasattr(bot, 'lavalink'): bot.lavalink = lavalink.Client(bot.user.id, connect_back=True) bot.lavalink.add_node('127.0.0.1', 2333, config.lavalink, 'br', 'pearl') bot.add_listener(bot.lavalink.voice_update_handler, 'on_socket_response') lavalink.add_event_hook(self.track_hook)
def __init__(self, bot: Bot): self.bot = bot addr = main_web_addr if dev else '127.0.0.1' lc = Client(bot.user.id, player=Player) lc.add_node(addr, 2333, main_password, 'ru', 'default-node') bot.add_listener(lc.voice_update_handler, 'on_socket_response') self.lavalink = lc self.bot.loop.create_task(self.initialize()) add_event_hook(update_queues, event=TrackEndEvent)
def __init__(self, bot: commands.Bot): super().__init__() class Command(bot.db.Entity): id = orm.PrimaryKey(int, auto=True) name = orm.Required(str) output_str = orm.Required(str) nsfw = orm.Required(bool) targetted = orm.Required(bool) help_text = orm.Required(str) self.Command = Command self.bot = bot bot.add_listener(self.setup, 'on_ready')
async def initialize(bot: Bot, host, password, rest_port, ws_port, timeout=30): """ Initializes the websocket connection to the lavalink player. .. important:: This function must only be called AFTER the bot has received its "on_ready" event! Parameters ---------- bot : Bot An instance of a discord.py `Bot` object. host : str The hostname or IP address of the Lavalink node. password : str The password of the Lavalink node. rest_port : int The port of the REST API on the Lavalink node. ws_port : int The websocket port on the Lavalink Node. timeout : int Amount of time to allow retries to occur, ``None`` is considered forever. """ global _loop _loop = bot.loop player_manager.user_id = bot.user.id player_manager.channel_finder_func = bot.get_channel register_event_listener(_handle_event) register_update_listener(_handle_update) lavalink_node = node.Node( _loop, dispatch, bot._connection._get_websocket, host, password, port=ws_port, rest=rest_port, user_id=player_manager.user_id, num_shards=bot.shard_count if bot.shard_count is not None else 1, ) await lavalink_node.connect(timeout=timeout) bot.add_listener(player_manager.on_socket_response) return lavalink_node
def setup(bot: Bot): # settings register('greet.channel', None, lambda x: True, False, 'The channel where greetings should be sent.', filter=channel_filter) register( 'greet.message', None, lambda x: True, False, 'The message new members will be greeted with. You may use ' 'the `{name}` token in your message and it will be replaced ' 'automatically with the member\'s username. The `{nl}` token ' 'will be replaced with a line break (new line).') bot.add_listener(on_member_join)
def setup(bot: commands.Bot): check_folders() check_files() n = Membership(bot) bot.add_listener(n.member_join, "on_member_join") bot.add_listener(n.member_leave, "on_member_remove") bot.add_listener(n.member_ban, "on_member_ban") bot.add_listener(n.member_unban, "on_member_unban") bot.add_cog(n)
def setup(self, bot: commands.Bot): """ Attach a fragment to a bot """ _L.debug("Fragment.setup: bot=%s; %d commands, %d events", bot, len(self.commands), len(self.events)) self.bot = bot for com in self.commands: bot.add_command(com) for func, name in self.events: if name == "task": bot.loop.create_task(func()) else: bot.add_listener(func, name)
def setup(bot: commands.Bot): extension = Owner(bot) bot.add_cog(extension) bot.add_listener(extension.on_message, "on_message") bot.add_listener(extension.on_message_edit, "on_message_edit") bot.add_listener(extension.on_typing, "on_typing")
async def setup(bot: commands.Bot): bot.add_listener(on_command_error)
def setup(bot: commands.Bot): extension = GitHub(bot) bot.add_cog(extension) bot.add_listener(extension.on_message, "on_message")
def setup(bot: commands.Bot) -> None: # TODO: add doc moderation = Moderation(bot) bot.add_listener(moderation.blacklisted_message, "on_message") bot.add_cog(moderation)
if result is not None: if 'limit_everyone' in result and len(before.roles) < len( after.roles): thelimit = int(result['limit_everyone']) # Because the @everyone role is included, which can't be deleted if (len(after.roles) - 1) > thelimit: # Now have to find the role that was added and remove it ids = {} for r in before.roles: ids[r.id] = r for r in after.roles: if r.id not in ids: await after.remove_roles( r, reason="Reached the role limit, which is " + str(thelimit) + " for everyone.") if "minimalist" in result and len(before.roles) < len(after.roles): if result["minimalist"]: delete_roles = after.roles[1:] for r in delete_roles: await after.remove_roles( r, reason="Role hierarchy management is on.") except: rc.captureException() client.add_listener(on_member_update, 'on_member_update') client.add_cog(DiscordBotsOrgAPI(client)) client.run(os.environ['DISCORD_TOKEN'])
def __init__(self, client: commands.Bot): self.client = client client.add_listener(self._on_member_join, "on_member_join") client.add_listener(self._on_message, "on_message")
"server_info_scopes": [707125794404565002], } TOKEN = environ["BOT_ACCESS_TOKEN"] # 環境変数から取得 bot.config = { "funcs": {}, "ready_is_road_once_flag": False, "loop_functions": [], "wkwm": home_config, "707027737335955476": home_config, } @bot.listen() async def on_ready(): if bot.config["ready_is_road_once_flag"]: return else: bot.config["ready_is_road_once_flag"] = True for g in bot.guilds: if g.rules_channel: bot.config[str(g.id)].update( {"rules_channel": f"{g.rules_channel.mention}"}) if bot.config.get("loop_functions"): for func in bot.config.get("loop_functions"): await func() bot.add_listener(on_ready) for extension in extensions: bot.load_extension(f"Cogs.{extension}") bot.run(TOKEN)
async def initialize( bot: Bot, host, password, ws_port, timeout=30, resume_key: Optional[str] = None, resume_timeout: int = 60, ): """ Initializes the websocket connection to the lavalink player. .. important:: This function must only be called AFTER the bot has received its "on_ready" event! Parameters ---------- bot : Bot An instance of a discord.py `Bot` object. host : str The hostname or IP address of the Lavalink node. password : str The password of the Lavalink node. ws_port : int The websocket port on the Lavalink Node. timeout : int Amount of time to allow retries to occur, ``None`` is considered forever. resume_key : Optional[str] A resume key used for resuming a session upon re-establishing a WebSocket connection to Lavalink. resume_timeout : inr How long the node should wait for a connection while disconnected before clearing all players. """ global _loop _loop = bot.loop player_manager.user_id = bot.user.id player_manager.channel_finder_func = bot.get_channel register_event_listener(_handle_event) register_update_listener(_handle_update) lavalink_node = node.Node( _loop, dispatch, bot._connection._get_websocket, host, password, port=ws_port, user_id=player_manager.user_id, num_shards=bot.shard_count if bot.shard_count is not None else 1, resume_key=resume_key, resume_timeout=resume_timeout, bot=bot, ) await lavalink_node.connect(timeout=timeout) lavalink_node._retries = 0 bot.add_listener(node.on_socket_response) bot.add_listener(_on_guild_remove, name="on_guild_remove") return lavalink_node
def setup(bot: commands.Bot): """Adds our error handler listener to the bot.""" bot.add_listener(on_command_error)
def __init__(self, client: commands.Bot): self.client = client client.add_listener(self._report_error, "on_command_error")
def __init__(self, client: commands.Bot): client.add_listener(self._on_member_updated, "on_member_update") self.client = client
async def initialize( bot: Bot, *, host, password, port: Optional[int] = None, timeout: float = 30, resume_key: Optional[str] = None, resume_timeout: float = 60, secured: bool = False, ): """ Initializes the websocket connection to the lavalink player. .. important:: This function must only be called AFTER the bot has received its "on_ready" event! Parameters ---------- bot : Bot An instance of a discord.py `Bot` object. host : str The hostname or IP address of the Lavalink node. password : str The password of the Lavalink node. port : Optional[int] The websocket port on the Lavalink Node. If not provided, it will use 80 for unsecured connections and 443 for secured. timeout : float Amount of time to allow retries to occur, ``None`` is considered forever. resume_key : Optional[str] A resume key used for resuming a session upon re-establishing a WebSocket connection to Lavalink. resume_timeout : float How long the node should wait for a connection while disconnected before clearing all players. secured: bool Whether to use the `wss://` and `https://` protocol. """ register_event_listener(_handle_event) register_update_listener(_handle_update) lavalink_node = node.Node( event_handler=dispatch, host=host, password=password, port=port, user_id=bot.user.id, num_shards=bot.shard_count or 1, resume_key=resume_key, resume_timeout=resume_timeout, bot=bot, secured=secured, ) await lavalink_node.connect(timeout=timeout) lavalink_node._retries = 0 bot.add_listener(_on_guild_remove, name="on_guild_remove") return lavalink_node