本文整理汇总了Python中discord.Server方法的典型用法代码示例。如果您正苦于以下问题:Python discord.Server方法的具体用法?Python discord.Server怎么用?Python discord.Server使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类discord
的用法示例。
在下文中一共展示了discord.Server方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: on_server_update
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Server [as 别名]
def on_server_update(self, before, after):
entries = []
if before.owner != after.owner:
entries.append('Server owner changed from {0.owner} (id {0.owner.id}) to {1.owner} (id {1.owner.id})')
if before.region != after.region:
entries.append('Server region changed from {0.region} to {1.region}')
if before.name != after.name:
entries.append('Server name changed from "{0.name}" to "{1.name}"')
if before.icon_url != after.icon_url:
entries.append('Server icon changed from {0.icon_url} to {1.icon_url}')
for e in entries:
await self.log(before, e.format(before, after))
示例2: say
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Server [as 别名]
def say(channel, *args, **kwargs):
if type(channel) is str:
# Server/Channel id
server_id, channel_id = channel.split("/")
channel = get_server(server_id).get_channel(channel_id)
if "client" in kwargs:
client = kwargs["client"]
del kwargs["client"]
else:
client = get_client(channel.server.id)
if asyncio.get_event_loop() != client.loop:
# Allows it to speak across shards
client.run_task(say, *((channel,) + args), **kwargs)
else:
try:
await client.send_message(channel, *args, **kwargs)
except discord.Forbidden as send_error:
raise SendMessagePermMissing(send_error)
示例3: archiveserver_full
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Server [as 别名]
def archiveserver_full(self, ctx, server_name):
"""Archive all messages from a server. Return as JSON."""
server = discord.utils.get(self.bot.servers, name=server_name)
if server is None:
await self.bot.say("Server not found.")
return
log = {}
for channel in server.channels:
await self.bot.type()
log[channel.id] = {
"id": channel.id,
"name": channel.name,
"messages": await self.channel_messages(channel, count=10000)
}
filename = "server_archive-{}.json".format(server.id)
with io.StringIO() as f:
json.dump(log, f, indent=4)
f.seek(0)
await ctx.bot.send_file(
ctx.message.channel,
f,
filename=filename
)
示例4: send_server_roles
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Server [as 别名]
def send_server_roles(self, server: Server):
"""Log server roles on datadog."""
if not self.tags:
return
roles = {}
for role in server.roles:
roles[role.id] = {'role': role, 'count': 0}
for member in server.members:
for role in member.roles:
roles[role.id]['count'] += 1
for role in server.roles:
role_count = roles[role.id]['count']
statsd.gauge(
'bot.roles.{}'.format(server.id),
role_count,
tags=[
*self.tags,
'role_name:' + role.name,
'role_id:' + role.id,
'server_id:' + server.id,
'server_name:' + server.name])
示例5: fetch
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Server [as 别名]
def fetch(self, url):
"""Fetch request."""
error_msg = None
try:
async with aiohttp.ClientSession() as session:
body = await self.fetch_with_session(session, url)
except asyncio.TimeoutError:
error_msg = 'Request timed out'
raise ClashRoyaleAPIError(message=error_msg)
except aiohttp.ServerDisconnectedError as err:
error_msg = 'Server disconnected error: {}'.format(err)
raise ClashRoyaleAPIError(message=error_msg)
except (aiohttp.ClientError, ValueError) as err:
error_msg = 'Request connection error: {}'.format(err)
raise ClashRoyaleAPIError(message=error_msg)
except json.JSONDecodeError:
error_msg = "Non JSON returned"
raise ClashRoyaleAPIError(message=error_msg)
else:
return body
finally:
if error_msg is not None:
raise ClashRoyaleAPIError(message=error_msg)
示例6: _find_target
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Server [as 别名]
def _find_target(self, server: discord.Server) -> discord.Member:
for i in server.members:
if self._target_name in i.name.lower():
return i
raise KeyError('Could not find memory with name {}'.format(self._target_name))
示例7: set_default
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Server [as 别名]
def set_default(self, on_off: bool = None):
"""
Sets whether logging is on or off where unset
Server overrides, global override, and attachments don't use this.
"""
if on_off is not None:
self.settings['default'] = on_off
if self.settings.get('default', False):
await self.bot.say("Logging is enabled by default.")
else:
await self.bot.say("Logging is disabled by default.")
self.save_json()
示例8: should_log
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Server [as 别名]
def should_log(self, location):
if self.settings.get('everything', False):
return True
default = self.settings.get('default', False)
if type(location) is discord.Server:
if location.id in self.settings:
loc = self.settings[location.id]
return loc.get('all', False) or loc.get('events', default)
elif type(location) is discord.Channel:
if location.server.id in self.settings:
loc = self.settings[location.server.id]
opts = [loc.get('all', False), loc.get(location.id, default)]
if location.type is discord.ChannelType.voice:
opts.append(loc.get('voice', False))
return any(opts)
elif type(location) is discord.PrivateChannel:
return self.settings.get('direct', default)
else: # can't log other types
return False
示例9: log
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Server [as 别名]
def log(self, location, text, timestamp=None, force=False, subfolder=None, mode='a'):
if not timestamp:
timestamp = datetime.utcnow()
if self.lock or not (force or self.should_log(location)):
return
path = PATH_LIST.copy()
entry = [timestamp.strftime(TIMESTAMP_FORMAT)]
rotation = self.settings.get('rotation')
if type(location) is discord.Server:
path += [location.id, 'server.log']
elif type(location) is discord.Channel:
serverid = location.server.id
entry.append('#' + location.name)
path += [serverid, location.id + '.log']
elif type(location) is discord.PrivateChannel:
path += ['direct', location.id + '.log']
else:
return
if subfolder:
path.insert(-1, str(subfolder))
text = text.replace('\n', '\\n')
entry.append(text)
if rotation:
path[-1] = self.format_rotation_string(timestamp, rotation, path[-1])
fname = os.path.join(*path)
handle = self.gethandle(fname, mode=mode)
await handle.write(' '.join(entry) + '\n')
示例10: on_voice_state_update
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Server [as 别名]
def on_voice_state_update(self, before, after):
if not self.should_log(before.server):
return
if before.voice_channel != after.voice_channel:
if before.voice_channel:
msg = "Voice channel leave: {0} (id {0.id})"
if after.voice_channel:
msg += ' moving to {1.voice_channel}'
await self.log(before.voice_channel, msg.format(before, after))
if after.voice_channel:
msg = "Voice channel join: {0} (id {0.id})"
if before.voice_channel:
msg += ', moved from {0.voice_channel}'
flags = self.get_voice_flags(after)
if flags:
msg += ', flags: %s' % ','.join(flags)
await self.log(after.voice_channel, msg.format(before, after))
if before.deaf != after.deaf:
verb = 'deafen' if after.deaf else 'undeafen'
await self.log(before.voice_channel, 'Server {0}: {1} (id {1.id})'.format(verb, before))
if before.mute != after.mute:
verb = 'mute' if after.mute else 'unmute'
await self.log(before.voice_channel, 'Server {0}: {1} (id {1.id})'.format(verb, before))
if before.self_deaf != after.self_deaf:
verb = 'deafen' if after.self_deaf else 'undeafen'
await self.log(before.voice_channel, 'Server self-{0}: {1} (id {1.id})'.format(verb, before))
if before.self_mute != after.self_mute:
verb = 'mute' if after.self_mute else 'unmute'
await self.log(before.voice_channel, 'Server self-{0}: {1} (id {1.id})'.format(verb, before))
示例11: _resolve_role_list
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Server [as 别名]
def _resolve_role_list(server: discord.Server, roles: list) -> list:
gen = (_role_from_string(server, name) for name in roles)
return list(filter(None, gen))
示例12: recensor_server_priv_exempt
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Server [as 别名]
def recensor_server_priv_exempt(self, ctx, priv_exempt: bool = None):
"""
Configures privileged user exemption
This setting acts as the default for when a filter's priv_exempt
this parameter is set to 'inherit'. If enabled, the server owner,
moderator role and admin role (according to [p]set) are ignored by
the filter.
"""
server = ctx.message.server
settings = self.settings.get(server.id)
if type(priv_exempt) not in (bool, type(None)):
priv_exempt = await ctx.command.do_conversion(ctx, bool, priv_exempt)
if not settings:
self.settings[server.id] = settings = ServerConfig(self)
self.save()
if priv_exempt is None:
priv_exempt = settings.priv_exempt
adj = 'currently'
elif settings.priv_exempt == priv_exempt:
adj = 'already'
else:
adj = 'now'
settings.priv_exempt = priv_exempt
self.save()
desc = 'enabled' if priv_exempt else 'disabled'
await self.bot.say('Server-wide privilege user exemption for is %s %s by default.' % (adj, desc))
示例13: get_all_players
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Server [as 别名]
def get_all_players(self, server: discord.Server):
return [self.get_player(m) for m in server.members]
示例14: server
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Server [as 别名]
def server(self) -> Optional[discord.Server]:
return self.cog.bot.get_server(self.server_id)
示例15: _add_event
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Server [as 别名]
def _add_event(self, name, command, dest_server, dest_channel, author, timedelta, repeat=False, start=None):
if isinstance(dest_server, discord.Server):
dest_server = dest_server.id
if isinstance(dest_channel, discord.Channel):
dest_channel = dest_channel.id
if isinstance(author, discord.User):
author = author.id
if dest_server not in self.events:
self.events[dest_server] = {}
if isinstance(start, datetime):
start = start.timestamp()
event_dict = {
'name' : name,
'channel' : dest_channel,
'author' : author,
'command' : command,
'timedelta' : timedelta,
'repeat' : repeat,
'starttime' : start or int(time.time())
}
log.debug('event dict:\n\t{}'.format(event_dict))
self.events[dest_server][name] = event_dict
e = Event(server=dest_server, **event_dict)
await self._put_event(e)
self.save_events()