Skip to content

Commit d0927c8

Browse files
committed
Format examples
1 parent a1b8a4a commit d0927c8

15 files changed

+34
-25
lines changed

examples/background_task.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
from discord.ext import tasks
2-
31
import discord
2+
from discord.ext import tasks
43

54

65
class MyClient(discord.Client):

examples/background_task_asyncio.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import discord
21
import asyncio
32

3+
import discord
4+
45

56
class MyClient(discord.Client):
67
def __init__(self, *args, **kwargs):

examples/basic_bot.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# This example requires the 'members' privileged intents
22

3+
import random
4+
35
import discord
46
from discord.ext import commands
5-
import random
67

78
description = """An example bot to showcase the discord.ext.commands extension
89
module.

examples/basic_voice.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import asyncio
22

3-
import discord
43
import youtube_dl
54

5+
import discord
66
from discord.ext import commands
77

88
# Suppress noise about console usage from errors

examples/custom_context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ async def get_context(self, message, *, cls=MyContext):
3434

3535
@bot.command()
3636
async def guess(ctx, number: int):
37-
""" Guess a random number from 1 to 6. """
37+
"""Guess a random number from 1 to 6."""
3838
# explained in a previous example, this gives you
3939
# a random number from 1-6
4040
value = random.randint(1, 6)

examples/edits.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import discord
21
import asyncio
32

3+
import discord
4+
45

56
class MyClient(discord.Client):
67
async def on_ready(self):

examples/guessing_game.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import discord
2-
import random
31
import asyncio
2+
import random
3+
4+
import discord
45

56

67
class MyClient(discord.Client):

examples/views/button_roles.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@ def __init__(self, role: discord.Role):
2020
"""
2121
A button for one role. `custom_id` is needed for persistent views.
2222
"""
23-
super().__init__(label=role.name,
24-
style=discord.enums.ButtonStyle.primary, custom_id=str(role.id))
23+
super().__init__(
24+
label=role.name,
25+
style=discord.enums.ButtonStyle.primary,
26+
custom_id=str(role.id),
27+
)
2528

2629
async def callback(self, interaction: discord.Interaction):
2730
"""This function will be called any time a user clicks on this button
@@ -47,11 +50,15 @@ async def callback(self, interaction: discord.Interaction):
4750
if role not in user.roles:
4851
# give the user the role if they don't already have it
4952
await user.add_roles(role)
50-
await interaction.response.send_message(f"🎉 You have been given the role {role.mention}", ephemeral=True)
53+
await interaction.response.send_message(
54+
f"🎉 You have been given the role {role.mention}", ephemeral=True
55+
)
5156
else:
5257
# else, take the role from the user
5358
await user.remove_roles(role)
54-
await interaction.response.send_message(f"❌ The {role.mention} role has been taken from you", ephemeral=True)
59+
await interaction.response.send_message(
60+
f"❌ The {role.mention} role has been taken from you", ephemeral=True
61+
)
5562

5663

5764
class ButtonRoleCog(commands.Cog):
@@ -65,8 +72,7 @@ def __init__(self, bot):
6572
# make sure to set the guild ID here to whatever server you want the buttons in
6673
@slash_command(guild_ids=[...], description="Post the button role message")
6774
async def post(self, ctx: commands.Context):
68-
"""Slash command to post a new view with a button for each role
69-
"""
75+
"""A slash command to post a new view with a button for each role"""
7076

7177
# timeout is None because we want this view to be persistent
7278
view = discord.ui.View(timeout=None)

examples/views/confirm.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
from discord.ext import commands
2-
31
import discord
2+
from discord.ext import commands
43

54

65
class Bot(commands.Bot):

examples/views/counter.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
from discord.ext import commands
2-
31
import discord
2+
from discord.ext import commands
43

54

65
class CounterBot(commands.Bot):

0 commit comments

Comments
 (0)