本文整理汇总了Python中discord.Role方法的典型用法代码示例。如果您正苦于以下问题:Python discord.Role方法的具体用法?Python discord.Role怎么用?Python discord.Role使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类discord
的用法示例。
在下文中一共展示了discord.Role方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: on_guild_role_update
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Role [as 别名]
def on_guild_role_update(self, before: Role, after: Role) -> None:
"""Syncs role with the database if any of the stored attributes were updated."""
if after.guild.id != constants.Guild.id:
return
was_updated = (
before.name != after.name
or before.colour != after.colour
or before.permissions != after.permissions
or before.position != after.position
)
if was_updated:
await self.bot.api_client.put(
f'bot/roles/{after.id}',
json={
'colour': after.colour.value,
'id': after.id,
'name': after.name,
'permissions': after.permissions.value,
'position': after.position,
}
)
示例2: _create_list
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Role [as 别名]
def _create_list(self, server): # A credit to calebj#7377 for helping me out here.
"""Creates the role list for a server"""
if 'colour' not in self.settings_dict[server.id]: # Backwards compatibility. *Sigh*
colour = 0x72198b
else:
colour = self.settings_dict[server.id]['colour']
embed = discord.Embed(description='**Role list:**', colour=colour)
for roleid, roledata in self.settings_dict[server.id]['roles'].items():
role = discord.utils.get(server.roles, id=roleid)
if not role:
continue
if roledata['uniquegroup'] > 0:
embed.add_field(name='%s (Unique, ID #%s)' % (role.name, roledata['uniquegroup']), value=self._price_string(roledata['price'], True))
else:
embed.add_field(name=role.name, value=self._price_string(roledata['price'], True))
return embed
示例3: create
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Role [as 别名]
def create(self, ctx, role: discord.Role, interval: NumberConverter, *items_or_number: data.ItemOrNumber):
"""Create a daily salary for a user with the given role.
The time interval is the interval which must pass before the user may collect the salary again, in seconds.
If a role with a salary is deleted, the salary will also be deleted.
For example
`rp!salary create @Bot Creator 3600 500` Will create a salary of $500 for a user hourly
`rp!salary create @Bot Creator 86400 Bananax3 Orangex4` Will create a salary of 3 Bananas and 4 Oranges for a user daily
Requires Bot Moderator or Bot Admin
"""
if not items_or_number:
await ctx.send(await _(ctx, "Missing argument, see rp!help salary create"))
return
sals = await self.bot.di.get_salaries(ctx.guild)
if len(items_or_number) == 1 and isinstance(items_or_number[0], int):
items_or_number = items_or_number[0]
sals[role.id] = {'int': interval, 'val': items_or_number}
await self.bot.di.update_salaries(ctx.guild, sals)
await ctx.send((await _(ctx, "Successfully created a daily salary of {} for {}")).format(items_or_number, role))
示例4: setup_starboard
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Role [as 别名]
def setup_starboard(self, ctx, channel: discord.Channel=None, emoji="⭐", role:discord.Role=None):
"""Sets the starboard channel, emoji and role"""
server = ctx.message.server
if channel is None:
channel = ctx.message.channel
if "<" in emoji and ">" in emoji:
emoji = await self.check_server_emojis(server, emoji)
if emoji is None:
await self.bot.send_message(ctx.message.channel, "That emoji is not on this server!")
return
else:
emoji = ":" + emoji.name + ":" + emoji.id
if role is None:
role = await self.get_everyone_role(server)
self.settings[server.id] = {"emoji": emoji,
"channel": channel.id,
"role": [role.id],
"threshold": 0,
"messages": [],
"ignore": []}
dataIO.save_json("data/star/settings.json", self.settings)
await self.bot.say("Starboard set to {}".format(channel.mention))
示例5: add_role
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Role [as 别名]
def add_role(self, ctx, role:discord.Role=None):
"""Add a role allowed to add messages to the starboard defaults to @everyone"""
server = ctx.message.server
if server.id not in self.settings:
await self.bot.send_message(ctx.message.channel,
"I am not setup for the starboard on this server!\
\nuse starboard set to set it up.")
return
everyone_role = await self.get_everyone_role(server)
if role is None:
role = everyone_role
if role.id in self.settings[server.id]["role"]:
await self.bot.send_message(ctx.message.channel, "{} can already add to the starboard!".format(role.name))
return
if everyone_role.id in self.settings[server.id]["role"] and role != everyone_role:
self.settings[server.id]["role"].remove(everyone_role.id)
self.settings[server.id]["role"].append(role.id)
dataIO.save_json("data/star/settings.json", self.settings)
await self.bot.send_message(ctx.message.channel, "Starboard role set to {}.".format(role.name))
示例6: role_ignore
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Role [as 别名]
def role_ignore(self, ctx, role:discord.Role):
"""Add or remove a role to be checked. Remove all roles to check everyone."""
server = ctx.message.server
server_roles = self.settings[server.id]["check_roles"]
channel = ctx.message.channel
added_role = False
everyone_role = await self.get_everyone_role(server)
if role.id in server_roles:
self.settings[server.id]["check_roles"].remove(role.id)
await self.bot.send_message(channel, "Now ignoring {}!".format(role.name))
added_role = True
if role.id not in server_roles and not added_role:
self.settings[server.id]["check_roles"].append(role.id)
await self.bot.send_message(channel, "Now checking {}!".format(role.name))
if len(server_roles) < 1:
self.settings[server.id]["check_roles"].append(everyone_role)
await self.bot.send_message(channel, "Now checking everyone!")
if len(server_roles) > 1 and everyone_role in server_roles:
self.settings[server.id]["check_roles"].remove(everyone_role)
dataIO.save_json(self.settings_file, self.settings)
示例7: add_server
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Role [as 别名]
def add_server(self, ctx, channel:discord.Channel=None, role:discord.Role=None, invite_link=None):
"""Set the server for activity checking"""
server = ctx.message.server
if channel is None:
channel = ctx.message.channel
if role is not None:
role = role.id
if role is None:
role = await self.get_everyone_role(server)
if server.id in self.log:
await self.bot.say("This server is already checking for activity!")
return
if invite_link is None:
await self.bot.say("You'll need to supply an invite link if you want one for members to rejoin")
self.settings[server.id] = {"channel": channel.id,
"check_roles": [role],
"time": 604800,
"invite": True,
"link": invite_link,
"rip_count": 0}
dataIO.save_json(self.settings_file, self.settings)
await self.build_list(ctx, server)
await self.bot.send_message(ctx.message.channel, "Sending activity check messages to {}".format(channel.mention))
示例8: uniquegroup
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Role [as 别名]
def uniquegroup(self, ctx, role: discord.Role, groupid: int):
"""Set a role to a unique group ID,
This means that a user cannot have more then one role from the same group.
Any role sharing the same ID will be considered a group.
GroupID 0 will not be considered unique and can share other roles."""
server = ctx.message.server
if role.id not in self.settings_dict[server.id]['roles']:
await self.bot.say('This role ins\'t in the buyrole list')
elif groupid < 0:
await self.bot.say('The group ID cannot be negative.')
else:
# Set the uniquegroup ID here, logic will remain in a subfunction of buyrole
self.settings_dict[server.id]['roles'][role.id]['uniquegroup'] = groupid
self.save_json()
if groupid == 0:
await self.bot.say('Unique Group ID set. {} isn\'t considered unique.'.format(role.name))
else:
await self.bot.say('Unique Group ID set. {} will now be unique in group ID {}'.format(role.name, groupid))
示例9: format_overwrite
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Role [as 别名]
def format_overwrite(target, channel, before, after):
target_str = 'Channel overwrites: {0.name} ({0.id}): '.format(channel)
target_str += 'role' if isinstance(target, discord.Role) else 'member'
target_str += ' {0.name} ({0.id})'.format(target)
if before:
bpair = [x.value for x in before.pair()]
if after:
apair = [x.value for x in after.pair()]
if before and after:
fmt = ' updated to values %i, %i (was %i, %i)'
return target_str + fmt % tuple(apair + bpair)
elif after:
return target_str + ' added with values %i, %i' % tuple(apair)
elif before:
return target_str + ' removed (was %i, %i)' % tuple(bpair)
示例10: _role_from_string
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Role [as 别名]
def _role_from_string(server, rolename, roles=None):
if roles is None:
roles = server.roles
else:
roles = [r for r in roles if isinstance(r, discord.Role)]
if rolename.isdigit():
role = discord.utils.get(roles, id=rolename)
if role:
log.debug("Role {} found from ID {}".format(role.name, rolename))
return role
rolename = rolename.lower()
role = discord.utils.find(lambda r: r.name.lower() == rolename, roles)
try:
log.debug("Role {} found from rolename {}".format(role.name, rolename))
except Exception:
log.debug("Role not found for rolename {}".format(rolename))
return role
示例11: protect_common
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Role [as 别名]
def protect_common(self, obj, protect=True):
if not isinstance(obj, (discord.Member, discord.Role)):
raise TypeError('Can only pass member or role objects.')
server = obj.server
id = ('r' if type(obj) is discord.Role else '') + obj.id
protected = self.duelists.get(server.id, {}).get("protected", [])
if protect == (id in protected):
return False
elif protect:
protected.append(id)
else:
protected.remove(id)
if server.id not in self.duelists:
self.duelists[server.id] = {}
self.duelists[server.id]['protected'] = protected
dataIO.save_json(JSON_PATH, self.duelists)
return True
示例12: addrole
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Role [as 别名]
def addrole(self, ctx, role: discord.Role):
"""
Sets a role to be managed by gameroles.
Roles with multiple words need to be surrounded in quotes.
The bot's highest role needs to be above the role that you are adding and the bot needs permission to manage roles.
"""
roledict = await self.config.guild(ctx.guild).roledict()
rid = str(role.id)
if rid in roledict:
return await ctx.send(
f'`{role.name}` is already managed by gameroles. '
f'Use `{ctx.prefix}gameroles addactivity` to add activities.'
)
roledict[role.id] = []
await self.config.guild(ctx.guild).roledict.set(roledict)
await ctx.send(
f'`{role.name}` is now managed by gameroles! '
f'Use `{ctx.prefix}gameroles addactivity` to add activities.'
)
if ctx.guild.id in self.cache:
del self.cache[ctx.guild.id]
示例13: delrole
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Role [as 别名]
def delrole(self, ctx, role: Union[discord.Role, int]):
"""
Stop a role from being managed by gameroles.
Roles with multiple words need to be surrounded in quotes.
Accepts the ID of the role in case it was deleted.
"""
roledict = await self.config.guild(ctx.guild).roledict()
if isinstance(role, discord.Role):
rid = str(role.id)
name = role.name
else:
rid = str(role)
name = rid
if rid not in roledict:
return await ctx.send(f'`{name}` is not managed by gameroles.')
del roledict[rid]
await self.config.guild(ctx.guild).roledict.set(roledict)
await ctx.send(f'`{name}` is no longer managed by gameroles!')
if ctx.guild.id in self.cache:
del self.cache[ctx.guild.id]
示例14: addactivity
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Role [as 别名]
def addactivity(self, ctx, role: discord.Role, activity: str):
"""
Add an activity to trigger a role.
Roles and activities with multiple words need to be surrounded in quotes.
You can get the name of your current activity with [p]gameroles currentactivity.
"""
roledict = await self.config.guild(ctx.guild).roledict()
rid = str(role.id)
if rid not in roledict:
return await ctx.send(f'`{role.name}` is not managed by gameroles.')
if activity in roledict[rid]:
return await ctx.send(f'`{activity}` already triggers `{role.name}`.')
roledict[rid].append(activity)
await self.config.guild(ctx.guild).roledict.set(roledict)
await ctx.send(f'`{role.name}` is now triggered by `{activity}`!')
if ctx.guild.id in self.cache:
del self.cache[ctx.guild.id]
示例15: delactivity
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Role [as 别名]
def delactivity(self, ctx, role: discord.Role, activity: str):
"""
Remove an activity from triggering a role.
Roles and activities with multiple words need to be surrounded in quotes.
You can get the name of your current activity with [p]gameroles currentactivity.
"""
roledict = await self.config.guild(ctx.guild).roledict()
rid = str(role.id)
if rid not in roledict:
return await ctx.send(f'`{role.name}` is not managed by gameroles.')
if activity not in roledict[rid]:
return await ctx.send(f'`{activity}` does not trigger `{role.name}`.')
roledict[rid].remove(activity)
await self.config.guild(ctx.guild).roledict.set(roledict)
await ctx.send(f'`{role.name}` is no longer triggered by `{activity}`!')
if ctx.guild.id in self.cache:
del self.cache[ctx.guild.id]