本文整理汇总了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()
示例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 :)")
示例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
示例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]`')
示例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
示例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)
示例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!'))
示例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
示例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))
示例10: convert
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Game [as 别名]
def convert(self, ctx, argument):
return discord.Game(name=argument)
示例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."
示例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)
示例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))
示例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))
示例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