本文整理匯總了Python中discord.Client.get_all_members方法的典型用法代碼示例。如果您正苦於以下問題:Python Client.get_all_members方法的具體用法?Python Client.get_all_members怎麽用?Python Client.get_all_members使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類discord.Client
的用法示例。
在下文中一共展示了Client.get_all_members方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_member
# 需要導入模塊: from discord import Client [as 別名]
# 或者: from discord.Client import get_all_members [as 別名]
def get_member(client: discord.Client, member_id: str):
""" Get a member from the specified ID. """
for member in client.get_all_members():
if member.id == member_id:
return member
return None
示例2: update_user_data
# 需要導入模塊: from discord import Client [as 別名]
# 或者: from discord.Client import get_all_members [as 別名]
def update_user_data(client: discord.Client):
""" Go through all registered members playing osu!, and update their data. """
global osu_tracking
# Go through each member playing and give them an "old" and a "new" subsection
# for their previous and latest user data
for member_id, profile in osu_config.data["profiles"].items():
def check_playing(m):
""" Check if a member has "osu!" in their Game name. """
# The member doesn't even match
if not m.id == member_id:
return False
# See if the member is playing
if m.game and "osu!" in m.game.name:
return True
return False
member = discord.utils.find(check_playing, client.get_all_members())
# If the member is not playing anymore, remove them from the tracking data
if not member:
if member_id in osu_tracking:
del osu_tracking[member_id]
continue
mode = get_mode(member_id).value
user_data = yield from api.get_user(u=profile, type="id", m=mode)
# Just in case something goes wrong, we skip this member (these things are usually one-time occurances)
if user_data is None:
continue
# User is already tracked
if member_id in osu_tracking:
# Move the "new" data into the "old" data of this user
osu_tracking[member_id]["old"] = osu_tracking[member_id]["new"]
else:
# If this is the first time, update the user's list of scores for later
scores = yield from api.get_user_best(u=profile, type="id", limit=score_request_limit, m=mode)
osu_tracking[member_id] = dict(member=member, scores=scores)
# Update the "new" data
osu_tracking[member_id]["new"] = user_data
示例3: on_ready
# 需要導入模塊: from discord import Client [as 別名]
# 或者: from discord.Client import get_all_members [as 別名]
def on_ready(client: discord.Client):
while not client.is_closed:
try:
yield from asyncio.sleep(update_interval)
# Go through all set channels (if they're online on discord) and update their status
for member_id, channel in twitch_channels.data["channels"].items():
member = discord.utils.find(lambda m: m.status is not discord.Status.offline and m.id == member_id,
client.get_all_members())
if member:
with aiohttp.ClientSession() as session:
response = yield from session.get(twitch_api + "/streams/" + channel)
if response:
json = yield from response.json() if response.status == 200 else {}
else:
json = {}
stream = json.get("stream")
if member_id in live_channels:
if not stream:
live_channels.pop(member_id)
else:
if stream:
live_channels[member_id] = stream
# Tell every mutual channel between the streamer and the bot that streamer started streaming
for server in client.servers:
if member in server.members:
m = "{0} went live at {1[channel][url]}.\n" \
"**{1[channel][display_name]}**: {1[channel][status]}\n" \
"*Playing {1[game]}*".format(member.mention, stream)
asyncio.async(client.send_message(server, m))
preview = yield from download_file(stream["preview"]["medium"])
yield from client.send_file(server, preview, filename="preview.jpg")
# Wait a second before sending a new server request
yield from asyncio.sleep(1)
except:
print_exc()
示例4: id_to_member
# 需要導入模塊: from discord import Client [as 別名]
# 或者: from discord.Client import get_all_members [as 別名]
def id_to_member(member_id: str, bot: discord.Client):
return discord.utils.find(lambda m: m.id == member_id, bot.get_all_members())
示例5: on_ready
# 需要導入模塊: from discord import Client [as 別名]
# 或者: from discord.Client import get_all_members [as 別名]
def on_ready(client: discord.Client):
global osu_tracking
if osu.data["key"] == "change to your api key":
logging.warning("osu! functionality is unavailable until an API key is provided")
sent_requests = 0
updated = 0
while not client.is_closed:
try:
yield from asyncio.sleep(update_interval)
# Go through all set channels playing osu! and update their status
for member_id, profile in osu.data["profiles"].items():
def check_playing(m):
if m.id == member_id and m.game:
if m.game.name.startswith("osu!"):
return True
return False
member = discord.utils.find(check_playing, client.get_all_members())
if member:
sent_requests += 1
params = {
"k": osu.data["key"],
"u": profile,
"type": "id",
"limit": request_limit
}
with aiohttp.ClientSession() as session:
response = yield from session.get(osu_api + "get_user_best", params=params)
scores = yield from response.json() if response.status == 200 else []
if scores:
# Go through all scores and see if they've already been tracked
if member_id in osu_tracking:
new_score = None
for score in scores:
if score not in osu_tracking[member_id]:
new_score = score
# Tell all mutual servers if this user set a nice play
if new_score:
for server in client.servers:
if member in server.members:
# Find some beatmap information
beatmap_search = yield from get_beatmaps(b=int(new_score["beatmap_id"]))
beatmap = get_beatmap(beatmap_search)
yield from client.send_message(
server,
format_new_score(member=member, score=new_score, beatmap=beatmap)
)
osu_tracking[member_id] = list(scores)
# Send info on how many requests were sent the last 30 minutes (60 loops)
updated += 1
if updated % updates_per_log() == 0:
logging.info("Requested osu! scores {} times in {} minutes.".format(sent_requests, logging_interval))
sent_requests = 0
except:
print_exc()