def create_event_button(bot: Bot, name: str, event: Event): async def new_button(self, button: Button, inter: MessageInteraction): member = inter.author guild = inter.guild for role in guild.roles: if role.name.lower() == name.replace("_", " "): break else: return if role in member.roles: await member.remove_roles(role) opt = "out" else: await member.add_roles(role) opt = "in" await inter.response.send_message( f"I have successfully opted you {opt} for {name} notifications!", ephemeral=True) icon = bot.get_emoji(event.icon) new_button.__name__ = name return button(custom_id=f"event {name}", emoji=icon)(new_button)
async def get_user(bot: commands.Bot, user_id: int) -> Optional[discord.User]: user = bot.get_user(user_id) if user is None: try: user = await bot.fetch_user(user_id) except: pass return user
def __init__(self, bot: commands.Bot): self.bot = bot self.old_help_command = bot.help_command bot.help_command = PaginatedHelpCommand() bot.help_command.cog = self self.activities = Activities(self.bot) self.update_presence.start()
async def get_guild(bot: commands.Bot, guild_id: int) -> Optional[discord.Guild]: guild = bot.get_guild(guild_id) if guild is None: try: guild = await bot.fetch_guild(guild_id) except: pass return guild
async def from_payload(cls, bot: Bot, payload: discord.RawReactionActionEvent): channel = bot.get_channel(payload.channel_id) if channel is None: return None if isinstance(channel, discord.DMChannel): return None guild = channel.guild if guild is None: return None member = payload.member if payload.member is not None else guild.get_member( payload.user_id) if member is None or member.bot: return None try: message: discord.Message = await channel.fetch_message( payload.message_id) if message is None: return None except discord.errors.NotFound: return None reply_to = None if message is not None and message.reference is not None and message.reference.message_id is not None: try: reply_to = await channel.fetch_message( message.reference.message_id) except discord.errors.NotFound: pass if payload.emoji.is_custom_emoji(): emoji = bot.get_emoji(payload.emoji.id) if emoji is None: emoji = payload.emoji else: emoji = payload.emoji.name return cls(channel, guild, member, message, reply_to, emoji)
async def from_payload(bot: Bot, payload: disnake.RawReactionActionEvent): channel: disnake.TextChannel = bot.get_channel(payload.channel_id) if channel is None: return None if channel.type is disnake.ChannelType.text: guild = channel.guild else: guild = bot.get_guild(config.guild_id) if guild is None: raise Exception("Nemůžu najít guildu podle config.guild_id") member = payload.member if payload.member is not None else guild.get_member(payload.user_id) if member is None or member.bot: return None try: message: disnake.Message = await channel.fetch_message(payload.message_id) if message is None: return None except disnake.errors.NotFound: return None reply_to = None if message is not None and message.reference is not None and message.reference.message_id is not None: try: reply_to = await channel.fetch_message(message.reference.message_id) except disnake.errors.NotFound: pass # Reply is there optional. if payload.emoji.is_custom_emoji(): emoji = bot.get_emoji(payload.emoji.id) if emoji is None: emoji = payload.emoji else: emoji = payload.emoji.name return ReactionContext(channel, guild, member, message, reply_to, emoji)
async def get_or_fetch_user(bot: Bot, user_id): user = bot.get_user(user_id) if user is None: user = await bot.fetch_user(user_id) return user
def setup(bot: commands.Bot) -> None: """Load the Github cog.""" bot.add_cog(Github(bot))
def setup(bot: commands.Bot): bot.add_cog(DueDiligenceCommands(bot))
def setup(bot: commands.Bot): bot.add_cog(DarkPoolShortsCommands(bot))
def setup(bot: commands.Bot): """ The setup function defining the jishaku.cog and jishaku extensions. """ bot.add_cog(Jishaku(bot=bot))
def setup(bot: Bot) -> None: """Loading the Gurkcraft cog.""" bot.add_cog(Gurkcraft(bot))
def setup(bot: commands.Bot) -> None: """Load the Cog.""" bot.add_cog(MakeGurkan(bot))
def setup(bot: commands.Bot): bot.add_cog(StocksSIACommands(bot))
def setup(bot: commands.Bot) -> None: """Load the Bonk cog.""" bot.add_cog(Bonk(bot))
def setup(bot: commands.Bot) -> None: """Error handler Cog load.""" bot.add_cog(CommandErrorHandler(bot))
def setup(bot: commands.Bot): bot.add_cog(DiscoverCommands(bot))
def setup(bot: commands.Bot): bot.add_cog(EconomyCommands(bot))
def setup(bot: commands.Bot): bot.add_cog(GovernmentCommands(bot))
def setup(bot: commands.Bot): bot.add_cog(Extension_Manager(bot))
def setup(bot: commands.Bot): bot.add_cog(Guild_Cog(bot))
def setup(bot: commands.Bot): bot.add_cog(HoyolabApiCog(bot))
async def get_or_fetch_channel(bot: Bot, channel_id): channel = bot.get_channel(channel_id) if channel is None: channel = await bot.fetch_channel(channel_id) return channel
def setup(bot: commands.Bot): bot.add_cog(CmdsCommands(bot))
def setup(bot: commands.Bot): bot.add_cog(EtfCommands(bot))
def setup(bot: commands.Bot): bot.add_cog(ScreenerCommands(bot))
def setup(bot: commands.Bot): bot.add_cog(TechnicalAnalysisCommands(bot))
def setup(bot: commands.Bot): bot.add_cog(Help_Cog(bot))