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


Python discord.Game方法代碼示例

本文整理匯總了Python中discord.Game方法的典型用法代碼示例。如果您正苦於以下問題:Python discord.Game方法的具體用法?Python discord.Game怎麽用?Python discord.Game使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在discord的用法示例。


在下文中一共展示了discord.Game方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_sync_cog_on_member_update_other

# 需要導入模塊: import discord [as 別名]
# 或者: from discord import Game [as 別名]
def test_sync_cog_on_member_update_other(self):
        """Members should not be patched if other attributes have changed."""
        self.assertTrue(self.cog.on_member_update.__cog_listener__)

        subtests = (
            ("activities", discord.Game("Pong"), discord.Game("Frogger")),
            ("nick", "old nick", "new nick"),
            ("status", discord.Status.online, discord.Status.offline),
        )

        for attribute, old_value, new_value in subtests:
            with self.subTest(attribute=attribute):
                self.cog.patch_user.reset_mock()

                before_member = helpers.MockMember(**{attribute: old_value}, guild=self.guild)
                after_member = helpers.MockMember(**{attribute: new_value}, guild=self.guild)

                await self.cog.on_member_update(before_member, after_member)

                self.cog.patch_user.assert_not_called() 
開發者ID:python-discord,項目名稱:bot,代碼行數:22,代碼來源:test_cog.py

示例2: event_gen

# 需要導入模塊: import discord [as 別名]
# 或者: from discord import Game [as 別名]
def event_gen(bot, force=False):
    bot.logger.info("One hour passed, we have to remove the previous event, and find a new one (maybe)")
    bot.current_event = next((item for item in bot.event_list if item['id'] == 0), None)  # Reset the event

    if force or random.randint(0, 100) <= 10:
        bot.logger.debug("[EVENT] A new event will be selected")
        event_id = random.randrange(1, len(bot.event_list))
        bot.logger.info(f"[EVENT] Selected event : {event_id}")
        bot.current_event = next((item for item in bot.event_list if item['id'] == event_id), None)  # Reset the event
        bot.logger.info(f"[EVENT] Selected event : {bot.current_event['name']}")

    else:
        # await bot.log(level=9, title="No new event rolled out", message=f"No event active until the next hour", where=None)

        bot.logger.info("[EVENT] No new event, see you next time!")

    bot.logger.debug("[EVENT] Updating playing status")
    game = discord.Game(name=f"{bot.current_event['name']}")
    await bot.log(level=10, title="New event rolled out", message=f"{bot.current_event['name']} is now the active event until the next hour", where=None)

    await bot.change_presence(status=discord.Status.online, activity=game)
    bot.logger.debug("[EVENT] Done :)") 
開發者ID:DuckHunt-discord,項目名稱:DHV3,代碼行數:24,代碼來源:spawning.py

示例3: switch_status

# 需要導入模塊: import discord [as 別名]
# 或者: from discord import Game [as 別名]
def switch_status(self, message):
        if not message.channel.is_private:
            current_game = str(message.server.me.game)
            current_status = message.server.me.status

            if self.last_change == None: #first run
                self.last_change = int(time.perf_counter())
                if len(self.statuses) > 0 and (current_game in self.statuses or current_game == "None"):
                    new_game = self.random_status(message)
                    await self.bot.change_presence(game=discord.Game(name=new_game), status=current_status)

            if message.author.id != self.bot.user.id:
                if abs(self.last_change - int(time.perf_counter())) >= self.settings["DELAY"]:
                    self.last_change = int(time.perf_counter())
                    new_game = self.random_status(message)
                    if new_game != None:
                        if current_game != new_game:
                            if current_game in self.statuses or current_game == "None": #Prevents rndstatus from overwriting song's titles or
                                await self.bot.change_presence(game=discord.Game(name=new_game), status=current_status) #custom statuses set with !set status 
開發者ID:Twentysix26,項目名稱:26-Cogs,代碼行數:21,代碼來源:rndstatus.py

示例4: _presence

# 需要導入模塊: import discord [as 別名]
# 或者: from discord import Game [as 別名]
def _presence(self, ctx, type=None, *, game=None):
        '''Change the bot's presence'''
        if type is None:
            await ctx.send(f'Usage: `{ctx.prefix}presence [game/stream/watch/listen] [message]`')
        else:
            if type.lower() == 'stream':
                await self.bot.change_presence(game=discord.Game(name=game, type=1, url='https://www.twitch.tv/a'), status='online')
                await ctx.send(f'Set presence to. `Streaming {game}`')
            elif type.lower() == 'game':
                await self.bot.change_presence(game=discord.Game(name=game))
                await ctx.send(f'Set presence to `Playing {game}`')
            elif type.lower() == 'watch':
                await self.bot.change_presence(game=discord.Game(name=game, type=3), afk=True)
                await ctx.send(f'Set presence to `Watching {game}`')
            elif type.lower() == 'listen':
                await self.bot.change_presence(game=discord.Game(name=game, type=2), afk=True)
                await ctx.send(f'Set presence to `Listening to {game}`')
            elif type.lower() == 'clear':
                await self.bot.change_presence(game=None)
                await ctx.send('Cleared Presence')
            else:
                await ctx.send('Usage: `.presence [game/stream/watch/listen] [message]`') 
開發者ID:cree-py,項目名稱:RemixBot,代碼行數:24,代碼來源:utility.py

示例5: status

# 需要導入模塊: import discord [as 別名]
# 或者: from discord import Game [as 別名]
def status(bot):
    gamename = ''
    while not bot.is_closed():
        if bot.is_ready():
            if bot.gamename:
                if bot.gamename != gamename:
                    log.info('Game changed to playing {}'.format(bot.gamename))
                    gamename = bot.gamename
                game = discord.Game(name=bot.gamename)
            else:
                if bot.gamename != gamename:
                    log.info('Removed Game Status')
                    gamename = bot.gamename
                game = None
            await bot.change_presence(game=game, status=discord.Status.invisible, afk=True)
        await asyncio.sleep(20)

# Load Extensions / Logger / Runbot 
開發者ID:lehnification,項目名稱:Discord-SelfBot,代碼行數:20,代碼來源:selfbot.py

示例6: countdown_status

# 需要導入模塊: import discord [as 別名]
# 或者: from discord import Game [as 別名]
def countdown_status(bot: commands.Bot) -> None:
    """Set the playing status of the bot to the minutes & hours left until the next day's challenge."""
    while is_in_advent():
        _, time_left = time_left_to_aoc_midnight()

        aligned_seconds = int(math.ceil(time_left.seconds / COUNTDOWN_STEP)) * COUNTDOWN_STEP
        hours, minutes = aligned_seconds // 3600, aligned_seconds // 60 % 60

        if aligned_seconds == 0:
            playing = f"right now!"
        elif aligned_seconds == COUNTDOWN_STEP:
            playing = f"in less than {minutes} minutes"
        elif hours == 0:
            playing = f"in {minutes} minutes"
        elif hours == 23:
            playing = f"since {60 - minutes} minutes ago"
        else:
            playing = f"in {hours} hours and {minutes} minutes"

        # Status will look like "Playing in 5 hours and 30 minutes"
        await bot.change_presence(activity=discord.Game(playing))

        # Sleep until next aligned time or a full step if already aligned
        delay = time_left.seconds % COUNTDOWN_STEP or COUNTDOWN_STEP
        await asyncio.sleep(delay) 
開發者ID:python-discord,項目名稱:seasonalbot,代碼行數:27,代碼來源:adventofcode.py

示例7: on_ready

# 需要導入模塊: import discord [as 別名]
# 或者: from discord import Game [as 別名]
def on_ready(self):

        # list of all the cogs.
        cogs = [cog for cog in os.listdir("FAITHFUL_FLEAS/cogs") if cog.endswith(".py")]

        for cog in cogs:
            try:
                # loading the cogs
                self.load_extension("faithful_fleas.cogs." + os.path.splitext(cog)[0])

            except Exception as e:
                # in case any cog/s did not load.
                logger.error(f"Could not load extension {cog} due to error:\n{e}")

        logger.info(f'Running as {self.user.name} with ID: {self.user.id}')
        await self.change_presence(activity=discord.Game(name='A sunny morning!')) 
開發者ID:python-discord,項目名稱:code-jam-5,代碼行數:18,代碼來源:__main__.py

示例8: __init__

# 需要導入模塊: import discord [as 別名]
# 或者: from discord import Game [as 別名]
def __init__(self, shard_ids=None, shard_count=None):
        super().__init__(
            shard_ids=shard_ids,
            shard_count=shard_count,
            max_messages=10000,
            activity=discord.Game(name="Embed your Discord server! Visit https://TitanEmbeds.com/")
        )
        self.setup_logger(shard_ids)
        self.aiosession = aiohttp.ClientSession(loop=self.loop)
        self.http.user_agent += ' TitanEmbeds-Bot'
        self.redisqueue = RedisQueue(self, config["redis-uri"])
        self.command = Commands(self, config)
        self.socketio = SocketIOInterface(self, config["redis-uri"])
        
        self.delete_list = deque(maxlen=100) # List of msg ids to prevent duplicate delete
        
        self.discordBotsOrg = None
        self.botsDiscordPw = None 
開發者ID:TitanEmbeds,項目名稱:Titan,代碼行數:20,代碼來源:bot.py

示例9: set_playing

# 需要導入模塊: import discord [as 別名]
# 或者: from discord import Game [as 別名]
def set_playing(self, title: str) -> None:
        await self.change_presence(activity=discord.Game(name=title)) 
開發者ID:r-spacex,項目名稱:SpaceXLaunchBot,代碼行數:4,代碼來源:discordclient.py

示例10: convert

# 需要導入模塊: import discord [as 別名]
# 或者: from discord import Game [as 別名]
def convert(self, ctx, argument):
        return discord.Game(name=argument) 
開發者ID:Rapptz,項目名稱:discord.py,代碼行數:4,代碼來源:converter.py

示例11: _changepresence

# 需要導入模塊: import discord [as 別名]
# 或者: from discord import Game [as 別名]
def _changepresence(self, status=None, msg=None):
        statuslevel = {'online': discord.Status.online, 'idle': discord.Status.idle, 'dnd': discord.Status.dnd}
        status = statuslevel.get(status)
        await self.bot.change_presence(status=status, activity=discord.Game(msg or "D&D 5e | !help"))
        return "Changed presence." 
開發者ID:avrae,項目名稱:avrae,代碼行數:7,代碼來源:adminUtils.py

示例12: __init__

# 需要導入模塊: import discord [as 別名]
# 或者: from discord import Game [as 別名]
def __init__(self, config):
        prefixes = ["+", "poll:", "Poll:", "POLL:"]
        super().__init__(
            command_prefix = prefixes,
            status = discord.Status.online,
            activity = discord.Game(name = "+help"))
        self.config = config

        self.remove_command("help")
        
        for extension in extensions:
            self.load_extension(extension) 
開發者ID:stayingqold,項目名稱:Poll-Bot,代碼行數:14,代碼來源:bot.py

示例13: on_ready

# 需要導入模塊: import discord [as 別名]
# 或者: from discord import Game [as 別名]
def on_ready(self):
        log.info(f"{self.bot.user.name}#{self.bot.user.discriminator} is online!")
        log.info("--------")
        embed = discord.Embed(
            title=f"[Cluster {self.bot.cluster}] Bot Ready", colour=0x00FF00, timestamp=datetime.datetime.utcnow(),
        )
        await self.bot.http.send_message(self.bot.config.event_channel, None, embed=embed.to_dict())
        await self.bot.change_presence(activity=discord.Game(name=self.bot.config.activity)) 
開發者ID:CHamburr,項目名稱:modmail,代碼行數:10,代碼來源:events.py

示例14: maintain_presence

# 需要導入模塊: import discord [as 別名]
# 或者: from discord import Game [as 別名]
def maintain_presence():
    # Loops through the activities specified in activities.csv
    activity = activities.get()
    await bot.change_presence(activity=discord.Game(name=activity)) 
開發者ID:eibex,項目名稱:reaction-light,代碼行數:6,代碼來源:bot.py

示例15: init

# 需要導入模塊: import discord [as 別名]
# 或者: from discord import Game [as 別名]
def init(cls, token=None):
        '''Starts the actual bot'''
        bot = cls()
        if token:
            to_use = token.strip('"')
        else:
            to_use = bot.token.strip('"')
        try:
            bot.run(to_use, activity=discord.Game(os.getenv('STATUS')), reconnect=True)
        except Exception as e:
            raise e 
開發者ID:kenng69,項目名稱:modmailbotkenng,代碼行數:13,代碼來源:bot.py


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