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


Python Client.find_channel方法代码示例

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


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

示例1: on_command

# 需要导入模块: from discord import Client [as 别名]
# 或者: from discord.Client import find_channel [as 别名]
def on_command(client: discord.Client, message: discord.Message, args: list):
    if args[0] == "!twitch":
        m = "Please see `!help twitch`."
        if len(args) > 1:
            # Assign a twitch channel to your name or remove it
            if args[1] == "set":
                if len(args) > 2:
                    twitch_channel = args[2]
                    twitch_channels.data["channels"][message.author.id] = twitch_channel
                    twitch_channels.save()
                    m = "Set your twitch channel to `{}`.".format(twitch_channel)
                else:
                    if message.author.id in twitch_channels.data["channels"]:
                        twitch_channels.data["channels"].pop(message.author.id)
                        twitch_channels.save()
                        m = "Twitch channel unlinked."

            # Return the member's or another member's twitch channel as a link
            elif args[1] == "get":
                if len(args) > 2:
                    member = client.find_member(message.server, args[2])
                else:
                    member = message.author

                if member:
                    # Send the link if member has set a channel
                    if member.id in twitch_channels.data["channels"]:
                        m = "{}'s twitch channel: https://secure.twitch.tv/{}.".format(
                            member.name,
                            twitch_channels.data["channels"][member.id]
                        )
                    else:
                        m = "No twitch channel assigned to {}!".format(member.name)
                else:
                    m = "Found no such member."

            # Set or get the twitch notify channel
            elif args[1] == "notify-channel":
                if message.author.permissions_in(message.channel).manage_server:
                    if len(args) > 2:
                        channel = client.find_channel(message.server, args[2])

                        if channel:
                            twitch_channels.data["notify-channel"] = channel.id
                            twitch_channels.save()
                            m = "Notify channel set to {}.".format(channel.mention)
                    else:
                        if "notify-channel" in twitch_channels.data:
                            twitch_channel = client.get_channel(twitch_channels.data["notify-channel"])
                            if twitch_channel:
                                m = "Twitch notify channel is {}.".format(twitch_channel)
                            else:
                                m = "The twitch notify channel no longer exists!"
                        else:
                            m = "A twitch notify channel has not been set."
                else:
                    m = "You need `Manage Server` to use this command."

        yield from client.send_message(message.channel, m)
开发者ID:EdwardBetts,项目名称:PCBOT,代码行数:61,代码来源:twitch.py

示例2: on_command

# 需要导入模块: from discord import Client [as 别名]
# 或者: from discord.Client import find_channel [as 别名]
def on_command(client: discord.Client, message: discord.Message, args: list):
    if args[0] == "!prank":
        name = "IT'S A"

        # Set the name and convert any mention to name (this ignores punctuation and converts "@PC," to "PC")
        if len(args) > 1 and len(message.clean_content) < 200:
            name_list = []

            for arg in args[1:]:
                steps = 3 if len(args) == 2 else 1
                member = client.find_member(message.server, arg, steps=steps)

                if member:
                    name_list.append(member.name)
                else:
                    channel = client.find_channel(message.server, arg, steps=0)

                    if channel:
                        name_list.append(channel.name)
                    else:
                        name_list.append(arg)

            name = " ".join(name_list)

        name = name.upper()

        # Initialize the image anhd font
        image_text = Image.new("RGBA", image_base.size, (255, 255, 255, 0))
        image_font = ImageFont.truetype(prank_path + "American Captain.ttf", 50)
        image_context = ImageDraw.Draw(image_text)

        # Set width and height and scale down when necessary
        width, height = image_context.textsize(name, image_font)
        font_size = 50

        if width > image_width:
            scaled_font = None

            while width > image_width:
                scaled_font = ImageFont.truetype(prank_path + "American Captain.ttf", font_size)
                width, height = image_context.textsize(name, scaled_font)
                font_size -= 1

            image_font = scaled_font

        # Set x and y coordinates for centered text
        x = (image_width - width) / 2
        y = (image_height - height / 2) - image_height / 1.3

        # Draw border
        shadow_offset = font_size // 25
        image_context.text((x - shadow_offset, y), name, font=image_font, fill=(0, 0, 0, 255))
        image_context.text((x + shadow_offset, y), name, font=image_font, fill=(0, 0, 0, 255))
        image_context.text((x, y - shadow_offset), name, font=image_font, fill=(0, 0, 0, 255))
        image_context.text((x, y + shadow_offset), name, font=image_font, fill=(0, 0, 0, 255))

        # Draw text
        image_context.text((x, y), name, font=image_font, fill=(255, 255, 255, 255))

        # Combine the base image with the font image
        image = Image.alpha_composite(image_base, image_text)

        # Save and send the image
        image.save(prank_path + "pranked.png")
        yield from client.send_file(message.channel, prank_path + "pranked.png")
开发者ID:EdwardBetts,项目名称:PCBOT,代码行数:67,代码来源:prank.py


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