本文整理汇总了Python中discord.Activity方法的典型用法代码示例。如果您正苦于以下问题:Python discord.Activity方法的具体用法?Python discord.Activity怎么用?Python discord.Activity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类discord
的用法示例。
在下文中一共展示了discord.Activity方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_loop
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Activity [as 别名]
def update_loop(self):
await self.bot.wait_until_ready()
while not self.bot.is_closed():
try:
await self.bot.change_presence(activity=discord.Activity(
name=f"{self.bot.config.prefix}help",
type=discord.ActivityType.watching
), afk=False)
if self.bot.config.dbl_token is not None and self.bot.is_primary_shard():
await self.update_discordbots_org()
except:
traceback.print_exc()
finally:
await asyncio.sleep(10 * 60)
示例2: activitytype
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Activity [as 别名]
def activitytype(self, ctx: commands.Context, *, activity: str):
"""
Choose which type of activity you want to see for the bot status.
Available types:
- playing
- watching
- listening
"""
activity_types = ["playing", "watching", "listening"]
if not activity.lower() in activity_types:
await ctx.send_help()
return
await self.config.activity_type.set(activity.lower())
await ctx.send(f"Activity type set to: {inline(activity.lower())}")
示例3: before_loop_presence
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Activity [as 别名]
def before_loop_presence(self):
await self.bot.wait_for_connected()
logger.line()
activity, status = await self.set_presence()
if activity is not None:
msg = f"Activity set to: {activity.type.name.capitalize()} "
if activity.type == ActivityType.listening:
msg += f"to {activity.name}."
else:
msg += f"{activity.name}."
logger.info(msg)
else:
logger.info("No activity has been set.")
if status is not None:
msg = f"Status set to: {status.value}."
logger.info(msg)
else:
logger.info("No status has been set.")
await asyncio.sleep(1800)
logger.info("Starting presence loop.")
示例4: playing
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Activity [as 别名]
def playing(self, ctx, media=""):
"""Update bot presence accordingly to invoke command"""
# Need URL for streaming
if not media:
media = f"{self.bot.config['PREFIX']}info | {self.bot.config['PREFIX']}help"
p_types = {'playing': 0, 'streaming': 1, 'listening': 2, 'watching': 3}
activity = discord.Activity(name=media, type=p_types[ctx.invoked_with])
# Keep trace of it
with open('config.yml', 'r') as file:
stuff = yaml_load(file)
stuff['STATUS_TYPE'] = p_types[ctx.invoked_with]
stuff['STATUS'] = media
with open('config.yml', 'w') as file:
yaml_dump(stuff, file)
self.bot.config = stuff
await self.bot.change_presence(activity=activity)
示例5: get_activity
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Activity [as 别名]
def get_activity(self, new_status: dict) -> tuple:
"""
This will return which avatar, status, and activity to use
"""
date = datetime.now()
activity = None
status = None
if date.month == 12 and date.day <= 25:
url = new_status["xmas"]
activity = discord.Activity(name="Merry Christmas!", type=discord.ActivityType.playing)
status = discord.Status.online
elif (date.month == 12 and date.day >= 30) or (date.month == 1 and date.day == 1):
url = new_status["link"]
activity = discord.Activity(name="Happy New Year!", type=discord.ActivityType.playing)
status = discord.Status.online
else:
url = new_status["link"]
activity = discord.Activity(
name=choice(new_status["game"]), type=choice(new_status["type"])
)
status = new_status["status"]
return status, activity, url
示例6: changegame
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Activity [as 别名]
def changegame(self, ctx, gameType: str, *, gameName: str):
'''Ändert das derzeit spielende Spiel (BOT OWNER ONLY)'''
gameType = gameType.lower()
if gameType == 'playing':
type = discord.Activity.playing
elif gameType == 'watching':
type = discord.Activity.watching
elif gameType == 'listening':
type = discord.Activity.listening
elif gameType == 'streaming':
type = discord.Activity.streaming
guildsCount = len(self.bot.guilds)
memberCount = len(list(self.bot.get_all_members()))
gameName = gameName.format(guilds = guildsCount, members = memberCount)
await self.bot.change_presence(activity=discord.Activity(type=type, name=gameName))
await ctx.send(f'**:ok:** Ändere das Spiel zu: {gameType} **{gameName}**')
示例7: _change_bot_status
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Activity [as 别名]
def _change_bot_status(self):
await self.bot.wait_until_ready()
while True:
await asyncio.sleep(10)
config_data = await self._get_config_data()
if not config_data["toggled"]:
# await self._set_default_status(config_data)
continue
if config_data["ip"] is None:
continue
data_players = await self._get_data(config_data["ip"], "players")
data_server = await self._get_data(config_data["ip"], "info")
if data_players is None or data_server is None:
await self._set_default_status(config_data)
continue
activity = discord.Activity(
name=config_data["text"].format(
**self._format_text_status(data_players, data_server, config_data)
),
type=self._activity_types(config_data["activity_type"]),
)
if config_data["activity_type"] == "streaming":
activity = discord.Streaming(
url=config_data["streamer"],
name=config_data["stream_title"].format(
**self._format_text_status(data_players, data_server, config_data)
),
)
await self.bot.change_presence(
status=self._status(config_data["status"]), activity=activity
)
示例8: activitystream
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Activity [as 别名]
def activitystream(
self, ctx: commands.Context, streamer: str = None, *, streamtitle: str = None
):
"""
Choose if you want to put a Twitch stream for the bot status.
Example: `[p]fivemset activitystream summit1g Come watch my stream!`
You can use some arguments:
- `{players}` will show how many players are connected.
- `{total}` will show the total players the server can have.
- `{server_ip}` will show the server ip.
Advanced example: `[p]fivemset activitystream summit1g {players}/{total} players are connected on LifeRP, check out my stream!`
"""
# Some logics from https://github.com/Cog-Creators/Red-DiscordBot/blob/V3/develop/redbot/core/core_commands.py#L1017
if streamtitle:
streamtitle = streamtitle.strip()
if "twitch.tv/" not in streamer:
streamer = "https://www.twitch.tv/" + streamer
async with self.config.all() as config:
config["streamer"] = streamer
config["stream_title"] = streamtitle
config["activity_type"] = "streaming"
await ctx.send(
"Activity stream set to:\n" + box(f"Streamer: {streamer}\nTitle : {streamtitle}")
)
elif streamer is None or streamtitle is None:
await ctx.send_help()
return
示例9: set_presence
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Activity [as 别名]
def set_presence(self, *, status=None, activity_type=None, activity_message=None):
if status is None:
status = self.bot.config.get("status")
if activity_type is None:
activity_type = self.bot.config.get("activity_type")
url = None
activity_message = (activity_message or self.bot.config["activity_message"]).strip()
if activity_type is not None and not activity_message:
logger.warning(
'No activity message found whilst activity is provided, defaults to "Modmail".'
)
activity_message = "Modmail"
if activity_type == ActivityType.listening:
if activity_message.lower().startswith("to "):
# The actual message is after listening to [...]
# discord automatically add the "to"
activity_message = activity_message[3:].strip()
elif activity_type == ActivityType.streaming:
url = self.bot.config["twitch_url"]
if activity_type is not None:
activity = discord.Activity(type=activity_type, name=activity_message, url=url)
else:
activity = None
await self.bot.change_presence(activity=activity, status=status)
return activity, status
示例10: on_ready
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Activity [as 别名]
def on_ready():
""" Confirm the bot is ready """
DISCORD_LOGGER.info("Bot started as %s! Username is %s and ID is %s",
BOT.user.name, BOT.user, BOT.user.id)
activity = Activity(name='Xiaomi updates', type=ActivityType.watching)
await BOT.change_presence(activity=activity)
# Load all modules in modules list
示例11: status_clockwork
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Activity [as 别名]
def status_clockwork(ev):
"""
:param ev: The event object referenced in the event.
:type ev: sigma.core.mechanics.event.SigmaEvent
"""
while True:
if ev.bot.is_ready():
if ev.bot.cfg.pref.status_rotation:
if not status_cache:
status_files = await ev.db[ev.db.db_nam].StatusFiles.find().to_list(None)
[status_cache.append(status_file.get('text')) for status_file in status_files]
if status_cache:
status = status_cache.pop(secrets.randbelow(len(status_cache)))
activity = discord.Activity(name=status, type=discord.ActivityType.playing)
# noinspection PyBroadException
try:
if ev.bot.cfg.pref.dev_mode:
status_type = discord.Status.dnd
else:
if ev.bot.latency > 5 or ev.bot.latency < 0:
status_type = discord.Status.dnd
elif ev.bot.latency > 2:
status_type = discord.Status.idle
else:
status_type = discord.Status.online
await ev.bot.change_presence(activity=activity, status=status_type)
except Exception:
pass
await asyncio.sleep(60)
示例12: setstatus
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Activity [as 别名]
def setstatus(cmd, pld):
"""
:param cmd: The command object referenced in the command.
:type cmd: sigma.core.mechanics.command.SigmaCommand
:param pld: The payload with execution data and details.
:type pld: sigma.core.mechanics.payload.CommandPayload
"""
if cmd.bot.cfg.pref.status_rotation:
response = error('I can\'t, automatic rotation is enabled.')
else:
status = ' '.join(pld.args)
activity = discord.Activity(type=discord.ActivityType.playing, name=status)
await cmd.bot.change_presence(activity=activity)
response = ok(f'New playing status set to {status}.')
await pld.msg.channel.send(embed=response)
示例13: on_ready
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Activity [as 别名]
def on_ready():
print(f'Bot is ready! Logged as in: {bot.user}')
await bot.change_presence(status=discord.Status.idle, activity=discord.Activity(type=discord.ActivityType.watching, name=f"your move | {os.getenv('PREFIX')}help"))
示例14: on_ready
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Activity [as 别名]
def on_ready():
bot.owner = await bot.fetch_user(SETTINGS.owner_id)
mongo = AsyncIOMotorClient(SETTINGS.mongo_db)
bot.db = mongo.pollmaster
bot.session = aiohttp.ClientSession()
print(bot.db)
# load emoji list
with open('utils/emoji-compact.json', encoding='utf-8') as emojson:
bot.emoji_dict = json.load(emojson)
# # check discord server configs
# try:
# db_server_ids = [entry['_id'] async for entry in bot.db.config.find({}, {})]
# for server in bot.guilds:
# if str(server.id) not in db_server_ids:
# # create new config entry
# await bot.db.config.update_one(
# {'_id': str(server.id)},
# {'$set': {'prefix': 'pm!', 'admin_role': 'polladmin', 'user_role': 'polluser'}},
# upsert=True
# )
# except:
# print("Problem verifying servers.")
# cache prefixes
bot.pre = {entry['_id']: entry.get('prefix', 'pm!') async for entry in bot.db.config.find({}, {'_id', 'prefix'})}
await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.listening, name="pm!help"))
print("Bot running.")
示例15: on_ready
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Activity [as 别名]
def on_ready(self):
self.owner = await self.fetch_user(SETTINGS.owner_id)
mongo = AsyncIOMotorClient(SETTINGS.mongo_db)
self.db = mongo.pollmaster
self.session = aiohttp.ClientSession()
with open('utils/emoji-compact.json', encoding='utf-8') as emojson:
self.emoji_dict = json.load(emojson)
self.pre = {entry['_id']: entry.get('prefix', 'pm!') async for entry in
self.db.config.find({}, {'_id', 'prefix'})}
await self.change_presence(activity=discord.Activity(type=discord.ActivityType.listening, name="pm!help"))
self.log.info(f'[Cluster#{self.cluster_name}] Ready called.')
self.pipe.send(1)
self.pipe.close()