wop commited on
Commit
0066b5e
1 Parent(s): f5902c7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -0
app.py CHANGED
@@ -71,6 +71,29 @@ async def verse(ctx):
71
  embed.set_footer(text="Created by Cosmos")
72
  await ctx.send(embed=embed)
73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  @bot.command()
75
  async def cmds(ctx):
76
  """Returns a list of commands and bot information."""
@@ -126,7 +149,38 @@ async def on_member_join(member):
126
 
127
  await channel.send(embed=embed)
128
 
 
 
 
 
 
 
 
 
 
 
 
129
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
  # running in thread
131
  def run_bot():
132
  if not DISCORD_TOKEN:
 
71
  embed.set_footer(text="Created by Cosmos")
72
  await ctx.send(embed=embed)
73
 
74
+ @bot.command()
75
+ @commands.has_permissions(kick_members=True)
76
+ async def kick(ctx, member: discord.Member, *, reason: Optional[str] = "No reason provided"):
77
+ try:
78
+ await member.kick(reason=reason)
79
+ await ctx.send(f"{member.mention} has been kicked. Reason: {reason}")
80
+ except discord.Forbidden:
81
+ await ctx.send("I don't have permission to kick members.")
82
+ except discord.HTTPException:
83
+ await ctx.send("An error occurred while trying to kick the member. Please try again later.")
84
+
85
+ @bot.command()
86
+ @commands.has_permissions(ban_members=True)
87
+ async def ban(ctx, member: discord.Member, *, reason: Optional[str] = "No reason provided"):
88
+ try:
89
+ await member.ban(reason=reason)
90
+ await ctx.send(f"{member.mention} has been banned. Reason: {reason}")
91
+ except discord.Forbidden:
92
+ await ctx.send("I don't have permission to ban members.")
93
+ except discord.HTTPException:
94
+ await ctx.send("An error occurred while trying to ban the member. Please try again later.")
95
+
96
+
97
  @bot.command()
98
  async def cmds(ctx):
99
  """Returns a list of commands and bot information."""
 
149
 
150
  await channel.send(embed=embed)
151
 
152
+ @bot.event
153
+ async def on_command_error(ctx, error):
154
+ if isinstance(error, commands.CommandNotFound):
155
+ await ctx.send("Sorry, I couldn't find that command. Use `$cmds` to see the list of available commands.")
156
+ elif isinstance(error, commands.MissingRequiredArgument):
157
+ await ctx.send("Oops! Looks like you're missing some required arguments.")
158
+ elif isinstance(error, commands.CheckFailure):
159
+ await ctx.send("You do not have the permissions to execute this command.")
160
+ else:
161
+ # Log the error to console or your logging system
162
+ print(f"An error occurred: {error}")
163
 
164
+ # Additional error handling for unexpected errors
165
+ @bot.event
166
+ async def on_error(event_method, *args, **kwargs):
167
+ # Log the error to console or your logging system
168
+ print(f"An error occurred in {event_method}: {sys.exc_info()}")
169
+
170
+ # Error handling for unhandled exceptions
171
+ @bot.event
172
+ async def on_command_error(ctx, error):
173
+ if isinstance(error, commands.CommandInvokeError):
174
+ original_error = error.original
175
+ if isinstance(original_error, discord.Forbidden):
176
+ await ctx.send("I don't have permissions to do that.")
177
+ elif isinstance(original_error, discord.HTTPException):
178
+ await ctx.send("An error occurred while processing the command. Please try again later.")
179
+ else:
180
+ # Log the error to console or your logging system
181
+ print(f"Error: {original_error}")
182
+ await ctx.send("An unexpected error occurred.")
183
+
184
  # running in thread
185
  def run_bot():
186
  if not DISCORD_TOKEN: