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


Python discord.Client方法代码示例

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


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

示例1: respond_to_card_names

# 需要导入模块: import discord [as 别名]
# 或者: from discord import Client [as 别名]
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) 
开发者ID:PennyDreadfulMTG,项目名称:Penny-Dreadful-Tools,代码行数:19,代码来源:command.py

示例2: single_card_text_internal

# 需要导入模块: import discord [as 别名]
# 或者: from discord import Client [as 别名]
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. 
开发者ID:PennyDreadfulMTG,项目名称:Penny-Dreadful-Tools,代码行数:21,代码来源:command.py

示例3: replace_emoji

# 需要导入模块: import discord [as 别名]
# 或者: from discord import Client [as 别名]
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 
开发者ID:PennyDreadfulMTG,项目名称:Penny-Dreadful-Tools,代码行数:19,代码来源:emoji.py

示例4: __init__

# 需要导入模块: import discord [as 别名]
# 或者: from discord import Client [as 别名]
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) 
开发者ID:r-spacex,项目名称:SpaceXLaunchBot,代码行数:17,代码来源:discordclient.py

示例5: notification_task

# 需要导入模块: import discord [as 别名]
# 或者: from discord import Client [as 别名]
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) 
开发者ID:r-spacex,项目名称:SpaceXLaunchBot,代码行数:10,代码来源:notifications.py

示例6: __init__

# 需要导入模块: import discord [as 别名]
# 或者: from discord import Client [as 别名]
def __init__(self, worker: 'DiscordWorker'):
        discord.Client.__init__(self)
        self._worker = worker
        self._ready = False
        self._logger = logging.getLogger(self.__class__.__name__) 
开发者ID:csvance,项目名称:armchair-expert,代码行数:7,代码来源:discord.py

示例7: wait_for_deletion

# 需要导入模块: import discord [as 别名]
# 或者: from discord import Client [as 别名]
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() 
开发者ID:python-discord,项目名称:bot,代码行数:39,代码来源:messages.py

示例8: single_card_text

# 需要导入模块: import discord [as 别名]
# 或者: from discord import Client [as 别名]
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) 
开发者ID:PennyDreadfulMTG,项目名称:Penny-Dreadful-Tools,代码行数:10,代码来源:command.py

示例9: post_cards

# 需要导入模块: import discord [as 别名]
# 或者: from discord import Client [as 别名]
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) 
开发者ID:PennyDreadfulMTG,项目名称:Penny-Dreadful-Tools,代码行数:37,代码来源:command.py

示例10: background_task

# 需要导入模块: import discord [as 别名]
# 或者: from discord import Client [as 别名]
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 
开发者ID:PennyDreadfulMTG,项目名称:Penny-Dreadful-Tools,代码行数:11,代码来源:bot.py

示例11: __init__

# 需要导入模块: import discord [as 别名]
# 或者: from discord import Client [as 别名]
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 
开发者ID:DXsmiley,项目名称:dismock,代码行数:9,代码来源:__init__.py

示例12: notify

# 需要导入模块: import discord [as 别名]
# 或者: from discord import Client [as 别名]
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 
开发者ID:flakas,项目名称:reconbot,代码行数:12,代码来源:discord.py

示例13: __init__

# 需要导入模块: import discord [as 别名]
# 或者: from discord import Client [as 别名]
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() 
开发者ID:sleibrock,项目名称:discord-bots,代码行数:10,代码来源:Bot.py

示例14: __init__

# 需要导入模块: import discord [as 别名]
# 或者: from discord import Client [as 别名]
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()) 
开发者ID:officialpiyush,项目名称:modmail-plugins,代码行数:7,代码来源:giveaway.py

示例15: __init__

# 需要导入模块: import discord [as 别名]
# 或者: from discord import Client [as 别名]
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()) 
开发者ID:officialpiyush,项目名称:modmail-plugins,代码行数:10,代码来源:report-user.py


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