#๐Ÿ”’ purge command not working in discord.py

45 messages ยท Page 1 of 1 (latest)

hexed moonBOT
#

@grim gyro

Python help channel opened

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.

grim gyro
#
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 purge(ctx, amount : int):
    if amount > 100: #an if statement to check if amount is greater than 100
        amount = 100 #if it is greater than 100, then just set the amount to 50 by default
    await ctx.channel.purge(limit= amount + 1)  
        
        
@bot.event
async def on_message(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')   


        


try:
  token = os.getenv("TOKEN") or ""
  if token == "":
    raise Exception("Please add your token to the Secrets pane.")
  bot.run(token)
except discord.HTTPException as e:
    if e.status == 429:
        print(
            "The Discord servers denied the connection for making too many requests"
        )
        print(
            "Get help from https://stackoverflow.com/questions/66724687/in-discord-py-how-to-solve-the-error-for-toomanyrequests"
        )
    else:
        raise e
#

gave the bot adminstarator

#

still doesnt work

#

no errors given

#

just not working when i type !purge

safe stump
#

because from the code im reading i see no errors

grim gyro
#

its solved

#

but

safe stump
#

alright

#

what was the issue

grim gyro
#

there is a proplem

#

in kicking members

safe stump
#

what problem

grim gyro
#

do i need to make a another post?

safe stump
#

no i think

grim gyro
#

k

hexed moonBOT
#

Hey @grim gyro!

It looks like you incorrectly specified a language for your code block.

Make sure you put your code on a new line following py. There must not be any spaces after py.

Here is an example of how it should look:
```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
You can **edit your original message** to correct your code block.
grim gyro
#
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(kick_members=True)
async def kick(ctx, member: discord.Member, *, reason):
    if member == "":
        await ctx.channel.send("Please mention a member to kick")
    else:
        await member.kick(reason=reason)
        await ctx.send(f'{member} 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```
#

the purge command s ok

#

the kick command is not ok

#

when i make !kick @a user

#

doesnt work

safe stump
#
    if member == "":
        await ctx.channel.send("Please mention a member to kick")
#

and this will never be true

#

as its assigned to be a discord.Member type

#

you can do it

#

if member == None:

#

instead of ""

grim gyro
#

ok

#

it makes an error

#

comaprsion to none should be cond is none

#

this is what it says

#

i fixed it

#

if member is none

#

not if member == none

#

wait

#

the !kick still doesnt work

summer knoll
#

are you dealing with the purge or kick command rn @grim gyro?

#

i can send my kick command if you'd like

hexed moonBOT
#
Python help channel closed

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.