mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-09-05 09:26:10 +00:00
Run black on all examples and require it for CI
This commit is contained in:
@ -10,15 +10,16 @@ intents.message_content = True
|
||||
|
||||
bot = commands.Bot(command_prefix=commands.when_mentioned, description="Nothing to see here!", intents=intents)
|
||||
|
||||
# the `hidden` keyword argument hides it from the help command.
|
||||
# the `hidden` keyword argument hides it from the help command.
|
||||
@bot.group(hidden=True)
|
||||
async def secret(ctx: commands.Context):
|
||||
"""What is this "secret" you speak of?"""
|
||||
if ctx.invoked_subcommand is None:
|
||||
await ctx.send('Shh!', delete_after=5)
|
||||
|
||||
|
||||
def create_overwrites(ctx, *objects):
|
||||
"""This is just a helper function that creates the overwrites for the
|
||||
"""This is just a helper function that creates the overwrites for the
|
||||
voice/text channels.
|
||||
|
||||
A `discord.PermissionOverwrite` allows you to determine the permissions
|
||||
@ -31,10 +32,7 @@ def create_overwrites(ctx, *objects):
|
||||
|
||||
# a dict comprehension is being utilised here to set the same permission overwrites
|
||||
# for each `discord.Role` or `discord.Member`.
|
||||
overwrites = {
|
||||
obj: discord.PermissionOverwrite(view_channel=True)
|
||||
for obj in objects
|
||||
}
|
||||
overwrites = {obj: discord.PermissionOverwrite(view_channel=True) for obj in objects}
|
||||
|
||||
# prevents the default role (@everyone) from viewing the channel
|
||||
# if it isn't already allowed to view the channel.
|
||||
@ -45,15 +43,16 @@ def create_overwrites(ctx, *objects):
|
||||
|
||||
return overwrites
|
||||
|
||||
|
||||
# since these commands rely on guild related features,
|
||||
# it is best to lock it to be guild-only.
|
||||
@secret.command()
|
||||
@commands.guild_only()
|
||||
async def text(ctx: commands.Context, name: str, *objects: typing.Union[discord.Role, discord.Member]):
|
||||
"""This makes a text channel with a specified name
|
||||
"""This makes a text channel with a specified name
|
||||
that is only visible to roles or members that are specified.
|
||||
"""
|
||||
|
||||
|
||||
overwrites = create_overwrites(ctx, *objects)
|
||||
|
||||
await ctx.guild.create_text_channel(
|
||||
@ -63,6 +62,7 @@ async def text(ctx: commands.Context, name: str, *objects: typing.Union[discord.
|
||||
reason='Very secret business.',
|
||||
)
|
||||
|
||||
|
||||
@secret.command()
|
||||
@commands.guild_only()
|
||||
async def voice(ctx: commands.Context, name: str, *objects: typing.Union[discord.Role, discord.Member]):
|
||||
@ -75,9 +75,10 @@ async def voice(ctx: commands.Context, name: str, *objects: typing.Union[discord
|
||||
await ctx.guild.create_voice_channel(
|
||||
name,
|
||||
overwrites=overwrites,
|
||||
reason='Very secret business.'
|
||||
reason='Very secret business.',
|
||||
)
|
||||
|
||||
|
||||
@secret.command()
|
||||
@commands.guild_only()
|
||||
async def emoji(ctx: commands.Context, emoji: discord.PartialEmoji, *roles: discord.Role):
|
||||
@ -94,7 +95,7 @@ async def emoji(ctx: commands.Context, emoji: discord.PartialEmoji, *roles: disc
|
||||
name=emoji.name,
|
||||
image=emoji_bytes,
|
||||
roles=roles,
|
||||
reason='Very secret business.'
|
||||
reason='Very secret business.',
|
||||
)
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user