當前位置: 首頁>>代碼示例>>Python>>正文


Python discord.Server方法代碼示例

本文整理匯總了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)) 
開發者ID:calebj,項目名稱:calebj-cogs,代碼行數:19,代碼來源:activitylog.py

示例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) 
開發者ID:MacDue,項目名稱:DueUtil,代碼行數:20,代碼來源:util.py

示例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
            ) 
開發者ID:smlbiobot,項目名稱:SML-Cogs,代碼行數:26,代碼來源:archive.py

示例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]) 
開發者ID:smlbiobot,項目名稱:SML-Cogs,代碼行數:24,代碼來源:ddlog.py

示例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) 
開發者ID:smlbiobot,項目名稱:SML-Cogs,代碼行數:25,代碼來源:racf_audit.py

示例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)) 
開發者ID:DXsmiley,項目名稱:dismock,代碼行數:7,代碼來源:__init__.py

示例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() 
開發者ID:calebj,項目名稱:calebj-cogs,代碼行數:17,代碼來源:activitylog.py

示例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 
開發者ID:calebj,項目名稱:calebj-cogs,代碼行數:28,代碼來源:activitylog.py

示例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') 
開發者ID:calebj,項目名稱:calebj-cogs,代碼行數:36,代碼來源:activitylog.py

示例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)) 
開發者ID:calebj,項目名稱:calebj-cogs,代碼行數:43,代碼來源:activitylog.py

示例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)) 
開發者ID:calebj,項目名稱:calebj-cogs,代碼行數:5,代碼來源:punish.py

示例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)) 
開發者ID:calebj,項目名稱:calebj-cogs,代碼行數:33,代碼來源:recensor.py

示例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] 
開發者ID:calebj,項目名稱:calebj-cogs,代碼行數:4,代碼來源:duel.py

示例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) 
開發者ID:calebj,項目名稱:calebj-cogs,代碼行數:4,代碼來源:captcha.py

示例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() 
開發者ID:calebj,項目名稱:calebj-cogs,代碼行數:35,代碼來源:scheduler.py


注:本文中的discord.Server方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。