Python discord 模块,Status() 实例源码
我们从Python开源项目中,提取了以下13个代码示例,用于说明如何使用discord.Status()。
def mods(self, ctx):
"""
Shows mods in this server.
A mod is defined as a human in this server with the "Kick Members" permission,or is a Dogbot Moderator.
"""
is_mod = lambda m: (m.guild_permissions.kick_members or checks.member_is_moderator(m)) and not m.bot
mods = [m for m in ctx.guild.members if is_mod(m)]
embed = discord.Embed(title='Moderators in ' + ctx.guild.name, color=discord.Color.blurple(),
description=f'There are {len(mods)} mod(s) total in {ctx.guild.name}.')
for status in discord.Status:
those_mods = [m for m in mods if m.status is status]
if not those_mods:
continue
embed.add_field(name=str(status).title(), value='\n'.join(str(m) for m in those_mods))
await ctx.send(embed=embed)
def c_presence(self, author, option=None):
"""
Changes presence status on discord
{prefix}presence <online/idle/dnd/invisible>
Invisible makes you appear offline.
Leave blank to reset presence to online.
"""
afk = False
if option is None:
option = 'online'
else:
option = option.lower()
if any(s == option for s in [e.value for e in discord.Status]):
if option == 'idle':
afk = True
await self.bot.change_presence(game=author.game, status=option, afk=afk)
return Response(":white_check_mark: Set presence to {}!".format(option))
else:
raise InvalidUsage()
def __init__(self, cfg):
super().__init__(
config.get_prefix,
description='Welcome. Welcome to my guild young ones. Please forgive the belated salutations. I am the holy program Excalibot!',
command_not_found='BAKA! That command does not exist!',
status=discord.Status[cfg['status']]
)
self.config = cfg
self.ready = False
self.session = db.Session()
self.check(self.permission_check)
def on_ready(self):
log.info('Logged in as %s (%s)', self.user, self.user.id)
game_config = self.config['game']
if game_config is not None:
game_config = dict(game_config) # copy,to write in formatted game name
game_config['name'] = game_config['name'].format(client=self, guild_count=len(self.guilds))
await self.change_presence(status=discord.Status[self.config['status']], game=discord.Game(**game_config)) # Must set status again,as leaving it empty will revert to Online
self.ready = True
def afk(ctx, *args, status=None, **kwargs):
await afk_send(ctx, 'afk_message', **kwargs)
if status == 'offline':
await ctx.bot.change_presence(status=discord.Status.invisible)
elif status is not None:
await ctx.bot.change_presence(status=discord.Status[status], game=discord.Game(name='AFK: ' + ','.join(args)))
def status(ctx):
rank, channel, message = await init_command(ctx.message)
if rank in ['ADMIN', 'MASTER']:
parameters = message.content.replace(commandPrefix + 'status ', "")
playmessage = parameters.split(" | ")[0]
status = parameters.split(" | ")[1]
await asyncio.sleep(1)
await client.change_presence(game=discord.Game(name=playmessage), status=discord.Status(status))
await client.send_message(channel, "Play message set to:``" + playmessage + "``,status set to:``" + status + "``")
else:
await missing_permissions_message(channel)
def on_ready():
global mainChannel, logsChannel, visible, databasePath, botOwner, Refresh
mainChannel = client.get_server(constants.Settings.mainServerID).get_channel(constants.Settings.mainChannelId)
logsChannel = client.get_server(constants.Settings.mainServerID).get_channel(constants.Settings.logsChannelId)
print('Logged in !')
botOwner = await client.get_user_info(str(constants.Settings.ownerdiscordId))
hello = False
if (datetime.Now().strftime('%H') == "02" and Refresh) or ((set(sys.argv) & set(["refresh"])) and Refresh):
await change_presence(status=discord.Status('dnd'), game=discord.Game(name='Booting ...'))
message = await client.send_message(mainChannel, "<:empty:317951266355544065> Updating stats ...")
#try:
print('Refreshing users stats ...')
update_stats.update_all_stats(conn, cursor)
Refresh = False
print(" - Done")
print('Creating new backup ...', end="")
create_backup()
print(" Done !")
await client.edit_message(message, "<:check:317951246084341761> Updating stats ... Done !")
# except:
# await client.edit_message(message,"<:xmark:317951256889131008> Updating stats ... Fail !")
if not set(sys.argv) & set(["dev"]):
await client.send_message(mainChannel, "<:online:317951041838514179> Uso!<:Bot:317951180737347587> is Now online !")
await change_presence(status=discord.Status('online'), game=discord.Game(name='Osu !'))
hello = True
if (set(sys.argv) & set(["online"])) and hello == False:
await client.send_message(mainChannel, "<:online:317951041838514179> Uso!<:Bot:317951180737347587> is Now online !")
if set(sys.argv) & set(["dev"]):
await change_presence(status=discord.Status('idle'), game=discord.Game(name='Dev mode'))
else:
await change_presence(status=discord.Status('online'), game=discord.Game(name='o!help'))
print ('Ready !')
def on_message(self, message: discord.Message):
# do not handle invisibility in dms
if isinstance(message.channel, discord.abc.PrivateChannel):
return
if await self.bot.config_is_set(message.guild, 'invisible_nag'):
if message.author.status is discord.Status.offline:
reply = 'hey {0.mention}! You\'re invisible. Stop being invisible,please. Thanks.'
await message.channel.send(reply.format(message.author))
def on_ready():
print('---------------------')
print('Logged in as :')
print('Username: ' + bot.user.name)
print('ID: ' + str(bot.user.id))
print('---------------------')
await bot.change_presence(game=discord.Game(name="manger des pommes ! .help !"), status=discord.Status("dnd"), afk=False)
if not hasattr(bot, 'uptime'):
bot.uptime = datetime.datetime.utcNow()
def __init__(self, bot, config, http):
self.declare_metric(
"opcodes", prometheus_client.Counter, 'Opcodes', ['opcode'])
self.declare_metric(
"dispatch_events", 'dispatch Events', ['event'])
self.declare_metric(
"command_triggers", 'Command Triggers', ['command'])
self.declare_metric(
"command_completions", 'Command Completions', ['command'])
self.declare_metric(
"command_errors", 'Command Errors', ['command', 'error'])
self.declare_metric(
"command_timing", prometheus_client.Histogram, 'Command Timing', ['command'])
self.declare_metric(
"server_count", prometheus_client.Gauge, "Server Count",
function=lambda: len(self.bot.guilds))
self.declare_metric(
"member_count", "Member Count", ['status'])
for status in discord.Status:
self.member_count.labels(status=status.name).set_function(
_count_members_fac(bot, status))
for opcode in OPCODE_NAMES.values():
self.opcodes.labels(opcode=opcode)
for dispatch_name in disPATCH_NAMES:
self.dispatch_events.labels(event=dispatch_name)
self._in_flight_ctx = {}
self.bot = bot
http.add_handler("GET", "/metrics", self.handle_metrics)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。