import os
import discord
import asyncio
from discord.ext import commands
import random
greetings = ["hello" , "hi" , "hey" , "wassup" , "sup" , "yo", "daddy", "mommy", "dad", "hi daddy" ]
hated_words = ["george sucks", "george is bad", "george is stupid", "george is dumb" , "george is a dumbass", ]
bot = commands.Bot(command_prefix='!', intents=discord.Intents.all())
@bot.command()
@commands.has_permissions(administrator=True)
async def kick(ctx, member: discord.Member, *, reason = None):
await member.kick(reason=reason)
await ctx.channel.sends(f"User {member.mention} has been kicked for {reason}")
@bot.command()
@commands.has_permissions(administrator=True)
async def purge(ctx, amount : int):
if amount > 100: #an if statement to check if amount is greater than 100
await ctx.channel.purge(limit=100) #deletes 100 messages
await ctx.channel.send("max number is 100 deleted 100 messages")
amount = 100 #if it is greater than 50, then just set the amount to 100 by default
await ctx.channel.purge(limit= amount + 1)
await ctx.channel.send(f"purged {amount} messages") #deletes the amount of messages specified
@bot.event
async def on_message(message):
await bot.process_commands(message)
if message.author == bot.user:
return
if message.content.startswith('$hello'):
await message.channel.send('Hello!')
if any(message.content.lower().strip() == word for word in greetings):
await message.channel.send('hi')
if any(message.content.lower().strip() == word for word in hated_words):
await message.channel.send('he is the best l bozo') ```
#๐ kick command is not working
49 messages ยท Page 1 of 1 (latest)
@upbeat mason
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Closes after a period of inactivity, or when you send !close.
Is there any error message?
Does purge work i heard on_message can somehow owervrite commands or something
i did it
Oh right
i asked in dsicord.py server
At the end of your on message
purge works
.
https://discordpy.readthedocs.io/en/latest/ext/commands/api.html?highlight=bot process#discord.ext.commands.Bot.process_commands You need to add this at the end
await bot.process_commands(message)
Otherwise text commands wonโt work
there is
Ok can you provide the full trace back error
Traceback (most recent call last):
File "/home/runner/moderation-bot/.pythonlibs/lib/python3.10/site-packages/discord/ext/commands/core.py", line 235, in wrapped
ret = await coro(*args, **kwargs)
File "/home/runner/moderation-bot/main.py", line 20, in kick
await member.kick(reason=reason)
File "/home/runner/moderation-bot/.pythonlibs/lib/python3.10/site-packages/discord/member.py", line 762, in kick
await self.guild.kick(self, reason=reason)
File "/home/runner/moderation-bot/.pythonlibs/lib/python3.10/site-packages/discord/guild.py", line 3648, in kick
await self._state.http.kick(user.id, self.id, reason=reason)
File "/home/runner/moderation-bot/.pythonlibs/lib/python3.10/site-packages/discord/http.py", line 739, in request
raise Forbidden(response, data)
discord.errors.Forbidden: 403 Forbidden (error code: 50013): Missing Permissions
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/runner/moderation-bot/.pythonlibs/lib/python3.10/site-packages/discord/ext/commands/bot.py", line 1350, in invoke
await ctx.command.invoke(ctx)
File "/home/runner/moderation-bot/.pythonlibs/lib/python3.10/site-packages/discord/ext/commands/core.py", line 1029, in invoke
await injected(*ctx.args, **ctx.kwargs) # type: ignore
File "/home/runner/moderation-bot/.pythonlibs/lib/python3.10/site-packages/discord/ext/commands/core.py", line 244, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: Forbidden: 403 Forbidden (error code: 50013): Missing Permissions
i aded administrator
it have
Is the user also an admin
Or is the user you are trying to kick above the bot
Bc then the bit isnโt able to
Bot
im the creator of the server
i should have administrator
im kicking a low member
(my alt)
The bot can only kick users that are lower than the bot account on the role hierarchy
ok so i put the role of the bot in the top of the server
it worke
but
it doesnt print the kicked user
await ctx.channel.sends(f"User {member.mention} has been kicked for {reason}")```
.sends() do you mean .send
Yes there is a way to unban
user = await bot.fetch_user(id)
await ctx.guild.unban(user)
if you mention a user you can use just the
await ctx.guild.unban(user)
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.