Python discord.Client() Examples
The following are 18
code examples of discord.Client().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
discord
, or try the search function
.
Example #1
Source File: command.py From Penny-Dreadful-Tools with GNU General Public License v3.0 | 6 votes |
def respond_to_card_names(message: Message, client: Client) -> None: # Don't parse messages with Gatherer URLs because they use square brackets in the querystring. if 'gatherer.wizards.com' in message.content.lower(): return compat = message.channel.type == ChannelType.text and client.get_user(268547439714238465) in message.channel.members queries = parse_queries(message.content, compat) if len(queries) > 0: await message.channel.trigger_typing() results = results_from_queries(queries) cards = [] for i in results: (r, mode, preferred_printing) = i if r.has_match() and not r.is_ambiguous(): cards.extend(cards_from_names_with_mode([r.get_best_match()], mode, preferred_printing)) elif r.is_ambiguous(): cards.extend(cards_from_names_with_mode(r.get_ambiguous_matches(), mode, preferred_printing)) await post_cards(client, cards, message.channel, message.author)
Example #2
Source File: command.py From Penny-Dreadful-Tools with GNU General Public License v3.0 | 6 votes |
def single_card_text_internal(client: Client, requested_card: Card, disable_emoji: bool) -> str: mana = emoji.replace_emoji('|'.join(requested_card.mana_cost or []), client) mana = mana.replace('|', ' // ') legal = ' — ' + emoji.info_emoji(requested_card, verbose=True) if disable_emoji: legal = '' if requested_card.get('mode', None) == '$': text = '{name} {legal} — {price}'.format(name=requested_card.name, price=card_price.card_price_string(requested_card), legal=legal) else: text = '{name} {mana} — {type}{legal}'.format(name=requested_card.name, mana=mana, type=requested_card.type_line, legal=legal) if requested_card.bugs: for bug in requested_card.bugs: text += '\n:beetle:{rank} bug: {bug}'.format(bug=bug['description'], rank=bug['classification']) if bug['last_confirmed'] < (dtutil.now() - datetime.timedelta(days=60)): time_since_confirmed = (dtutil.now() - bug['last_confirmed']).total_seconds() text += ' (Last confirmed {time} ago.)'.format(time=dtutil.display_time(time_since_confirmed, 1)) return text # See #5532 and #5566.
Example #3
Source File: emoji.py From Penny-Dreadful-Tools with GNU General Public License v3.0 | 6 votes |
def replace_emoji(text: str, client: Client) -> str: if text is None: return '' output = text symbols = re.findall(r'\{([A-Z0-9/]{1,3})\}', text) for symbol in symbols: name = symbol name = name.replace('/', '') if len(name) == 1: if re.fullmatch('[0-9]', name): name = '0' + name else: name = name + name emoji = find_emoji(name, client) if emoji is not None: output = output.replace('{' + symbol + '}', str(emoji)) return output
Example #4
Source File: starboard.py From modmail-plugins with GNU General Public License v3.0 | 5 votes |
def __init__(self, bot): self.bot: discord.Client = bot self.db = bot.plugin_db.get_partition(self) self.channel = None self.stars = 2 self.user_blacklist = list() self.channel_blacklist = list() asyncio.create_task(self._set_val())
Example #5
Source File: discordclient.py From SpaceXLaunchBot with MIT License | 5 votes |
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) logging.info("Client initialised") self.ds = storage.DataStore(config.PICKLE_DUMP_LOCATION) logging.info("Data storage initialised") if platform.system() == "Linux": self.loop.add_signal_handler( signal.SIGTERM, lambda: self.loop.create_task(self.shutdown()) ) logging.info("Signal handler for SIGTERM registered") self.loop.create_task(notifications.notification_task(self)) discordhealthcheck.start(self)
Example #6
Source File: quote.py From modmail-plugins with GNU General Public License v3.0 | 5 votes |
def __init__(self, bot): self.bot: discord.Client = bot self.db = bot.plugin_db.get_partition(self) self.i18n = Translator("")
Example #7
Source File: tags.py From modmail-plugins with GNU General Public License v3.0 | 5 votes |
def __init__(self, bot): self.bot: discord.Client = bot self.db = bot.plugin_db.get_partition(self)
Example #8
Source File: report-user.py From modmail-plugins with GNU General Public License v3.0 | 5 votes |
def __init__(self, bot): self.bot: discord.Client = bot self.db = bot.plugin_db.get_partition(self) self.blacklist = [] self.channel = None self.message = "Thanks for reporting, our Staff will look into it soon." self.current_case = 1 asyncio.create_task(self._set_config())
Example #9
Source File: giveaway.py From modmail-plugins with GNU General Public License v3.0 | 5 votes |
def __init__(self, bot): self.bot: discord.Client = bot self.db = bot.plugin_db.get_partition(self) self.active_giveaways = {} asyncio.create_task(self._set_giveaways_from_db())
Example #10
Source File: Bot.py From discord-bots with MIT License | 5 votes |
def __init__(self, name): super(ChatBot, self).__init__(name) self.actions = dict() self.client = Client() self.token = self.read_key() # load up the ban list self._load_bans()
Example #11
Source File: discord.py From reconbot with MIT License | 5 votes |
def notify(self, text, options={}): if 'channel' in options: channel_id = options['channel_id'] else: channel_id = self.channel_id self.client = discord.Client() loop = asyncio.get_event_loop() loop.run_until_complete(self._send_message(channel_id, text)) self.client = None
Example #12
Source File: __init__.py From dismock with MIT License | 5 votes |
def __init__(self, client: discord.Client, channel: discord.Channel, target: discord.User) -> None: self.client = client # The discord.py client object self.channel = channel # The channel the test is running in self.target = target # The bot which we are testing
Example #13
Source File: bot.py From Penny-Dreadful-Tools with GNU General Public License v3.0 | 5 votes |
def background_task(func: Callable) -> Callable: async def wrapper(self: discord.Client) -> None: try: await self.wait_until_ready() await func(self) except Exception: # pylint: disable=broad-except await self.on_error(func.__name__) TASKS.append(wrapper) return wrapper
Example #14
Source File: command.py From Penny-Dreadful-Tools with GNU General Public License v3.0 | 5 votes |
def post_cards( client: Client, cards: List[Card], channel: Messageable, replying_to: Optional[Member] = None, additional_text: str = '' ) -> None: if len(cards) == 0: await post_no_cards(channel, replying_to) return not_pd = configuration.get_list('not_pd') disable_emoji = str(channel.id) in not_pd or (getattr(channel, 'guild', None) is not None and str(channel.guild.id) in not_pd) cards = uniqify_cards(cards) if len(cards) > MAX_CARDS_SHOWN: cards = cards[:DEFAULT_CARDS_SHOWN] if len(cards) == 1: text = single_card_text_internal(client, cards[0], disable_emoji) else: text = ', '.join('{name} {legal} {price}'.format(name=card.name, legal=((emoji.info_emoji(card)) if not disable_emoji else ''), price=((card_price.card_price_string(card, True)) if card.get('mode', None) == '$' else '')) for card in cards) if len(cards) > MAX_CARDS_SHOWN: image_file = None else: with channel.typing(): image_file = await image_fetcher.download_image_async(cards) if image_file is None: text += '\n\n' if len(cards) == 1: text += emoji.replace_emoji(cards[0].oracle_text, client) else: text += 'No image available.' text += additional_text if image_file is None: await send(channel, text) else: await send_image_with_retry(channel, image_file, text)
Example #15
Source File: command.py From Penny-Dreadful-Tools with GNU General Public License v3.0 | 5 votes |
def single_card_text(client: Client, channel: TextChannel, args: str, author: Member, f: Callable[[Card], str], command: str, show_legality: bool = True) -> None: c = await single_card_or_send_error(channel, args, author, command) if c is not None: name = c.name info_emoji = emoji.info_emoji(c, show_legality=show_legality) text = emoji.replace_emoji(f(c), client) message = f'**{name}** {info_emoji} {text}' await send(channel, message)
Example #16
Source File: discord.py From armchair-expert with MIT License | 5 votes |
def __init__(self, worker: 'DiscordWorker'): discord.Client.__init__(self) self._worker = worker self._ready = False self._logger = logging.getLogger(self.__class__.__name__)
Example #17
Source File: notifications.py From SpaceXLaunchBot with MIT License | 5 votes |
def notification_task(client: discord.Client) -> None: """An async task to send out launching soon & launch info notifications.""" await client.wait_until_ready() logging.info("Starting") while not client.is_closed(): await _check_and_send_notifs(client) await asyncio.sleep(ONE_MINUTE * config.NOTIF_TASK_API_INTERVAL)
Example #18
Source File: messages.py From bot with MIT License | 3 votes |
def wait_for_deletion( message: Message, user_ids: Sequence[Snowflake], deletion_emojis: Sequence[str] = (Emojis.trashcan,), timeout: float = 60 * 5, attach_emojis: bool = True, client: Optional[Client] = None ) -> None: """ Wait for up to `timeout` seconds for a reaction by any of the specified `user_ids` to delete the message. An `attach_emojis` bool may be specified to determine whether to attach the given `deletion_emojis` to the message in the given `context` A `client` instance may be optionally specified, otherwise client will be taken from the guild of the message. """ if message.guild is None and client is None: raise ValueError("Message must be sent on a guild") bot = client or message.guild.me if attach_emojis: for emoji in deletion_emojis: await message.add_reaction(emoji) def check(reaction: Reaction, user: Member) -> bool: """Check that the deletion emoji is reacted by the appropriate user.""" return ( reaction.message.id == message.id and str(reaction.emoji) in deletion_emojis and user.id in user_ids ) with contextlib.suppress(asyncio.TimeoutError): await bot.wait_for('reaction_add', check=check, timeout=timeout) await message.delete()