You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Ignores if a command is being executed by a bot or by the bot itself
97
99
ifmessage.author==bot.userormessage.author.bot:
98
100
return
99
-
# Ignores if a command is being executed by a blacklisted user
100
-
withopen("blacklist.json") asfile:
101
-
blacklist=json.load(file)
102
-
ifmessage.author.idinblacklist["ids"]:
103
-
return
104
101
awaitbot.process_commands(message)
105
102
106
103
107
104
# The code in this event is executed every time a command has been *successfully* executed
108
105
@bot.event
109
-
asyncdefon_command_completion(ctx):
110
-
fullCommandName=ctx.command.qualified_name
106
+
asyncdefon_slash_command(ctx: SlashContext):
107
+
fullCommandName=ctx.name
111
108
split=fullCommandName.split(" ")
112
109
executedCommand=str(split[0])
113
110
print(
114
-
f"Executed {executedCommand} command in {ctx.guild.name} (ID: {ctx.message.guild.id}) by {ctx.message.author} (ID: {ctx.message.author.id})")
111
+
f"Executed {executedCommand} command in {ctx.guild.name} (ID: {ctx.guild.id}) by {ctx.author} (ID: {ctx.author.id})")
115
112
116
113
117
114
# The code in this event is executed every time a valid commands catches an error
118
115
@bot.event
119
116
asyncdefon_command_error(context, error):
120
-
ifisinstance(error, commands.CommandOnCooldown):
121
-
minutes, seconds=divmod(error.retry_after, 60)
122
-
hours, minutes=divmod(minutes, 60)
123
-
hours=hours%24
124
-
embed=discord.Embed(
125
-
title="Hey, please slow down!",
126
-
description=f"You can use this command again in {f'{round(hours)} hours'ifround(hours) >0else''}{f'{round(minutes)} minutes'ifround(minutes) >0else''}{f'{round(seconds)} seconds'ifround(seconds) >0else''}.",
Copy file name to clipboardExpand all lines: cogs/fun.py
+15-79
Original file line number
Diff line number
Diff line change
@@ -3,19 +3,17 @@
3
3
Description:
4
4
This is a template to create your own discord bot in python.
5
5
6
-
Version: 2.7
6
+
Version: 3.0
7
7
"""
8
8
9
-
importasyncio
10
9
importjson
11
10
importos
12
-
importrandom
13
11
importsys
14
12
15
13
importaiohttp
16
14
importdiscord
17
15
fromdiscord.extimportcommands
18
-
fromdiscord.ext.commandsimportBucketType
16
+
fromdiscord_slashimportcog_ext, SlashContext
19
17
20
18
ifnotos.path.isfile("config.json"):
21
19
sys.exit("'config.json' not found! Please add it and try again.")
@@ -28,24 +26,21 @@ class Fun(commands.Cog, name="fun"):
28
26
def__init__(self, bot):
29
27
self.bot=bot
30
28
31
-
"""
32
-
Why 1 and 86400?
33
-
-> Because the user should be able to use the command *once* every *86400* seconds
34
-
35
-
Why BucketType.user?
36
-
-> Because the cool down only affects the current user, if you want other types of cool downs, here are they:
37
-
- BucketType.default for a global basis.
38
-
- BucketType.user for a per-user basis.
39
-
- BucketType.server for a per-server basis.
40
-
- BucketType.channel for a per-channel basis.
41
-
"""
42
-
43
-
@commands.command(name="dailyfact")
44
-
@commands.cooldown(1, 86400, BucketType.user)
45
-
asyncdefdailyfact(self, context):
29
+
@cog_ext.cog_slash(
30
+
name="randomfact",
31
+
description="Get a random fact."
32
+
)
33
+
asyncdefrandomfact(self, context: SlashContext):
46
34
"""
47
-
Get a daily fact, command can only be ran once every day per user.
35
+
Get a random fact.
48
36
"""
37
+
38
+
# This is, for now, only temporary
39
+
withopen("blacklist.json") asfile:
40
+
blacklist=json.load(file)
41
+
ifcontext.author.idinblacklist["ids"]:
42
+
return
43
+
49
44
# This will prevent your bot from stopping everything when doing a web request - see: https://discordpy.readthedocs.io/en/stable/faq.html#how-do-i-make-a-web-request
0 commit comments