本文整理汇总了Python中discord.Client.find_member方法的典型用法代码示例。如果您正苦于以下问题:Python Client.find_member方法的具体用法?Python Client.find_member怎么用?Python Client.find_member使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类discord.Client
的用法示例。
在下文中一共展示了Client.find_member方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: on_command
# 需要导入模块: from discord import Client [as 别名]
# 或者: from discord.Client import find_member [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)
示例2: on_command
# 需要导入模块: from discord import Client [as 别名]
# 或者: from discord.Client import find_member [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")
示例3: on_command
# 需要导入模块: from discord import Client [as 别名]
# 或者: from discord.Client import find_member [as 别名]
def on_command(client: discord.Client, message: discord.Message, args: list):
if args[0] == "!osu":
m = "Please see `!help osu`."
if len(args) > 1:
# Assign an osu! profile to your name or remove it
if args[1] == "set":
if len(args) > 2:
profile = " ".join(args[2:])
params = {
"k": osu.data["key"],
"u": profile
}
with aiohttp.ClientSession() as session:
response = yield from session.get(osu_api + "get_user", params=params)
user = yield from response.json() if response.status == 200 else []
if user:
# Clear the scores when changing user
if message.author.id in osu_tracking:
osu_tracking.pop(message.author.id)
osu.data["profiles"][message.author.id] = user[0]["user_id"]
osu.save()
m = "Set your osu! profile to `{}`.".format(user[0]["username"])
else:
m = "User {} does not exist.".format(profile)
else:
if message.author.id in osu.data["profiles"]:
osu.data["profiles"].pop(message.author.id)
osu.save()
m = "osu! profile unlinked."
# Return the member's or another member's osu! profile as a link and upload a signature
elif args[1] == "get":
if len(args) > 2:
member = client.find_member(message.server, " ".join(args[2:]))
else:
member = message.author
if member:
if member.id in osu.data["profiles"]:
user_id = osu.data["profiles"][member.id]
# Set the signature color to that of the role color
color = "pink" if member.color is discord.Color.default() else member.color
# Download and upload the signature
params = {
"colour": color,
"uname": user_id,
"pp": 1,
"countryrank": True,
"xpbar": True
}
signature = yield from download_file("http://lemmmy.pw/osusig/sig.php", **params)
yield from client.send_file(message.channel, signature, filename="sig.png")
m = "https://osu.ppy.sh/u/{}".format(user_id)
else:
m = "No osu! profile assigned to {}!".format(member.name)
else:
m = "Found no such member."
elif args[1] == "test":
beatmap_search = yield from get_beatmaps(b=713442)
beatmap = get_beatmap(beatmap_search)
m = "```" + beatmap + "```"
# # Set or get the osu! 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:
# osu.data["notify-channel"][message.server.id] = channel.id
# osu.save()
# m = "Notify channel set to {}.".format(channel.mention)
# else:
# if "notify-channel" in osu.data:
# twitch_channel = client.get_channel(osu.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)