本文整理汇总了Python中discord.utils.get方法的典型用法代码示例。如果您正苦于以下问题:Python utils.get方法的具体用法?Python utils.get怎么用?Python utils.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类discord.utils
的用法示例。
在下文中一共展示了utils.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_user_premium
# 需要导入模块: from discord import utils [as 别名]
# 或者: from discord.utils import get [as 别名]
def get_user_premium(self, user_id, command_id):
guild = self.bot.get_guild(self.bot.config.main_server)
if not guild:
return
member = guild.get_member(user_id)
if not member:
return
if user_id in self.bot.config.admins or user_id in self.bot.config.owners:
amount = 1000
elif utils.get(member.roles, id=self.bot.config.premium5):
amount = 5
elif utils.get(member.roles, id=self.bot.config.premium3):
amount = 3
elif utils.get(member.roles, id=self.bot.config.premium1):
amount = 1
else:
amount = 0
payload = {"output": amount, "command_id": command_id}
await self.bot.redis.execute("PUBLISH", self.ipc_channel, json.dumps(payload))
示例2: _welcome_set
# 需要导入模块: from discord import utils [as 别名]
# 或者: from discord.utils import get [as 别名]
def _welcome_set(self, ctx, *, message):
"""You can use $user to mention the member who joins"""
server = ctx.message.server.id
channel_mentions = ctx.message.channel_mentions
if server not in self.welcome_messages:
self.welcome_messages[server] = {}
if len(channel_mentions) == 0:
channel = ctx.message.server.default_channel
else:
poss_mention = message.split(" ")[0]
if not re.compile(r'<#([0-9]+)>').match(poss_mention):
channel = ctx.message.server.default_channel
else:
channel = utils.get(channel_mentions, mention=poss_mention)
message = message[len(channel.mention) + 1:] # for the space
self.welcome_messages[server][channel.id] = message
fileIO("data/botinfo/welcome.json", "save", self.welcome_messages)
await self.bot.say('Member join message on '
'{} set to:\n\n{}'.format(channel.mention, message))
示例3: forcemention
# 需要导入模块: from discord import utils [as 别名]
# 或者: from discord.utils import get [as 别名]
def forcemention(self, ctx: commands.Context, role: str, *, message=""):
"""
Mentions that role, regardless if it's unmentionable
"""
role_obj = get(ctx.guild.roles, name=role)
if role_obj is None:
await ctx.maybe_send_embed("Couldn't find role named {}".format(role))
return
if not role_obj.mentionable:
await role_obj.edit(mentionable=True)
await ctx.send("{}\n{}".format(role_obj.mention, message), **SANITIZE_ROLES_KWARG)
await asyncio.sleep(5)
await role_obj.edit(mentionable=False)
else:
await ctx.send("{}\n{}".format(role_obj.mention, message), **SANITIZE_ROLES_KWARG)
示例4: event_handler
# 需要导入模块: from discord import utils [as 别名]
# 或者: from discord.utils import get [as 别名]
def event_handler(self):
channel = self.bot.redis.pubsub_channels[bytes(self.ipc_channel, "utf-8")]
while await channel.wait_message():
payload = await channel.get_json(encoding="utf-8")
if payload.get("action"):
if payload.get("scope") != "bot":
continue
if payload.get("args"):
self.bot.loop.create_task(self.run_action(payload, True))
else:
self.bot.loop.create_task(self.run_action(payload, False))
if payload.get("output") and payload["command_id"] in self._messages:
self._messages[payload["command_id"]].append(payload["output"])
示例5: remove_rank_roles
# 需要导入模块: from discord import utils [as 别名]
# 或者: from discord.utils import get [as 别名]
def remove_rank_roles(member):
"""Remove the member's rank/level roles."""
for rId in id_ranks:
if has_role(member, rId):
await member.remove_roles(get(member.guild.roles, id=rId))
示例6: remove_sub_role
# 需要导入模块: from discord import utils [as 别名]
# 或者: from discord.utils import get [as 别名]
def remove_sub_role(member):
"""Removes the member's sub role."""
await member.remove_roles(get(member.guild.roles, id=id_sub))
示例7: remove_contrib_role
# 需要导入模块: from discord import utils [as 别名]
# 或者: from discord.utils import get [as 别名]
def remove_contrib_role(member):
"""Remove the user's contrib role."""
await member.remove_roles(get(member.guild.roles, id=id_contrib))
示例8: remove_verified_role
# 需要导入模块: from discord import utils [as 别名]
# 或者: from discord.utils import get [as 别名]
def remove_verified_role(member):
"""Remove the user's verified role."""
await member.remove_roles(get(member.guild.roles, id=id_verified))
# Update a member's roles.
示例9: add_role
# 需要导入模块: from discord import utils [as 别名]
# 或者: from discord.utils import get [as 别名]
def add_role(member, id):
"""Add the role to the member."""
await member.add_roles(get(member.guild.roles, id=id))
示例10: _welcome_remove
# 需要导入模块: from discord import utils [as 别名]
# 或者: from discord.utils import get [as 别名]
def _welcome_remove(self, ctx, channel):
server = ctx.message.server.id
channel_mentions = ctx.message.channel_mentions
if server not in self.welcome_messages:
return
channel = utils.get(channel_mentions, mention=channel)
if channel is None:
await self.bot.say('Invalid channel.')
return
if channel.id in self.welcome_messages[server]:
del self.welcome_messages[server][channel.id]
self.save_welcome()
示例11: supporter
# 需要导入模块: from discord import utils [as 别名]
# 或者: from discord.utils import get [as 别名]
def supporter(self, ctx: CommandContext):
gugui = self.bot.get_guild(385848724628439062)
supporters = [member for member in gugui.members if
utils.get(member.roles, id=388689757909024769)]
supporter = ""
for us in supporters:
supporter = f"{supporter}\n{us.name}#{us.discriminator}"
await ctx.channel.send(
f"Here is a list of all generous donors who have supported the bot here:```{supporter}```")
示例12: on_ready
# 需要导入模块: from discord import utils [as 别名]
# 或者: from discord.utils import get [as 别名]
def on_ready(self):
print('bot ready')
self.channel = utils.get(self.get_all_channels(), name='codejam5')
示例13: handle
# 需要导入模块: from discord import utils [as 别名]
# 或者: from discord.utils import get [as 别名]
def handle(request):
name = request.match_info.get('name', "Anonymous")
await bot.channel.send(name)
return web.Response(text=name)
示例14: xkcd
# 需要导入模块: from discord import utils [as 别名]
# 或者: from discord.utils import get [as 别名]
def xkcd(self, ctx: Context, number: str = None):
"""
Fetches xkcd comics.
If number is left blank, automatically fetches the latest comic.
If number is set to '?', a random comic is fetched.
"""
# Creates endpoint URI
if number is None or number == "?":
endpoint = "https://xkcd.com/info.0.json"
else:
endpoint = f"https://xkcd.com/{number}/info.0.json"
# Fetches JSON data from endpoint
async with ClientSession() as session:
async with session.get(endpoint) as response:
data = await response.json()
# Updates comic number
if number == "?":
number = randint(1, int(data["num"])) # noqa: B311
endpoint = f"https://xkcd.com/{number}/info.0.json"
async with ClientSession() as session:
async with session.get(endpoint) as response:
data = await response.json()
else:
number = data["num"]
# Creates date object (Sorry, but I'm too tired to use datetime.)
date = f"{data['day']}/{data['month']}/{data['year']}"
# Creates Rich Embed, populates it with JSON data and sends it.
comic = Embed()
comic.title = data["safe_title"]
comic.set_footer(text=data["alt"])
comic.set_image(url=data["img"])
comic.url = f"https://xkcd.com/{number}"
comic.set_author(
name="xkcd",
url="https://xkcd.com/",
icon_url="https://xkcd.com/s/0b7742.png",
)
comic.add_field(name="Number:", value=number)
comic.add_field(name="Date:", value=date)
comic.add_field(name="Explanation:", value=f"https://explainxkcd.com/{number}")
await ctx.send(embed=comic)
示例15: add_quote_to_db
# 需要导入模块: from discord import utils [as 别名]
# 或者: from discord.utils import get [as 别名]
def add_quote_to_db(self, quote: Message):
"""
Adds a quote message ID to the database, and attempts to identify the author of the quote.
"""
author_id = None
if quote.author.id == QUOTES_BOT_ID:
if not quote.embeds:
return
embed = quote.embeds[0]
icon_url = embed.author.icon_url
if type(icon_url) == embeds._EmptyEmbed or "twimg" in icon_url:
author_id = QUOTES_BOT_ID
elif "avatars" in icon_url:
try:
author_id = int(icon_url.split("/")[-2])
except ValueError:
author_id = 0
else:
author_info = embed.author.name.split("#")
if len(author_info) == 1:
author_info.append("0000")
author = get(
quote.guild.members,
name=author_info[0],
discriminator=author_info[1],
)
author_id = author.id if author is not None else None
else:
author_id = quote.mentions[0].id if quote.mentions else None
async with self.bot.pool.acquire() as connection:
if author_id is not None:
await connection.execute(
"INSERT INTO quotes(quote_id, author_id) VALUES($1, $2) ON CONFLICT DO NOTHING",
quote.id,
author_id,
)
else:
await connection.execute(
"INSERT INTO quotes(quote_id) VALUES($1) ON CONFLICT DO NOTHING",
quote.id,
)
print(f"Quote ID: {quote.id} has been added to the database.")