#🔒 error

63 messages · Page 1 of 1 (latest)

patent lynxBOT
#

@steel dawn

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.

steel dawn
#

Exception has occurred: ExtensionFailed
Extension 'commands.ban' raised an error: TypeError: command() got an unexpected keyword argument 'reason'
File "C:\Users\yunus\OneDrive\Desktop\v8 bot\Masaüstü\123\commands\ban.py", line 5, in <module>
class Moderation(commands.Cog):
File "C:\Users\yunus\OneDrive\Desktop\v8 bot\Masaüstü\123\commands\ban.py", line 9, in Moderation
@app_commands.command(name='ban', reason=None)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: command() got an unexpected keyword argument 'reason'

The above exception was the direct cause of the following exception:

File "C:\Users\yunus\OneDrive\Desktop\v8 bot\Masaüstü\123\bot.py", line 23, in setup_hook
await bot.load_extension(f'commands.{filename[:-3]}')
File "C:\Users\yunus\OneDrive\Desktop\v8 bot\Masaüstü\123\bot.py", line 27, in <module>
bot.run('')
discord.ext.commands.errors.ExtensionFailed: Extension 'commands.ban' raised an error: TypeError: command() got an unexpected keyword argument 'reason'

inner barn
#

command() function is getting an unexpected keyword argument reason. this is because the reason parameter is not a valid argument for the command() decorator.

#

give whole code

steel dawn
#

Which file should I assign?

inner barn
steel dawn
inner barn
#

both

#

1 at time

steel dawn
#

ban.py;```py

commands/moderation.py

from discord.ext import commands
from discord import app_commands
import discord
class Moderation(commands.Cog):
def init(self, bot):
self.bot = bot

@app_commands.command(name='ban', reason=None) 
@app_commands.checks.has_permissions(ban_members=True)
async def ban(self, ctx, member: discord.Member,*, reason=None):
    try:
       await member.ban(reason=reason)
       await discord.Interaction.response.send_message(f'{member} - just got banned for {reason} (so silly goose)')
    except:
      print('im too lazy to continue ur code ,_,') 
   

@app_commands.command(name='unban', reason=None)
@app_commands.checks.has_permissions(ban_members=True)
async def unban(self, ctx, *, user_id: int):
    try:
        user = await self.bot.fetch_user(user_id)
        await ctx.guild.unban(user)
        await ctx.send(f'{user} Yasağı kaldırıldı')
    except discord.NotFound:
        await ctx.send(f'Kullanıcı ID {user_id} yasaklı kullanıcılar arasında bulunamadı.')
    except discord.Forbidden:
        await ctx.send("Bu kişiyi Yasaklayamazsınız. Yetkim yeterli değil.")
    except discord.HTTPException as e:
        await ctx.send(f"Bir hata oluştu: {str(e)}")

async def setup(bot):
await bot.add_cog(Moderation(bot))

#

bot.py;```py
import discord
from discord.ext import commands
import os

intents = discord.Intents.default()
intents.message_content = True

bot = commands.Bot(command_prefix='!', intents=intents)

@bot.event
async def on_ready():
print(f'Bot olarak giriş yapıldı: {bot.user.name}')
# Slash komutlarını sadece bir kez senkronize etmek için on_ready olayında çağırıyoruz
try:
synced = await bot.tree.sync()
print(f'Senkronize edilen komut sayısı: {len(synced)}')
except Exception as e:
print(f'Senkronizasyon hatası: {e}')

async def setup_hook():
for filename in os.listdir('./commands'):
if filename.endswith('.py'):
await bot.load_extension(f'commands.{filename[:-3]}')

bot.setup_hook = setup_hook

bot.run('
')````

inner barn
#

the issue is that the reason parameter should be defined within the function, not as a parameter of the @app_commands.command decorator.

steel dawn
inner barn
#

docs

steel dawn
#

?

inner barn
#

documentation

inner barn
#

remove the field in first decorator

steel dawn
#

I don't know exactly what this means in decorator in my own language.

inner barn
#

@app_commands.command(name='unban', reason=None)
to
@app_commands.command(name='unban')

steel dawn
#

Exception has occurred: ExtensionFailed
Extension 'commands.ban' raised an error: TypeError: command() got an unexpected keyword argument 'reason'
File "C:\Users\yunus\OneDrive\Desktop\v8 bot\Masaüstü\123\commands\ban.py", line 8, in <module>
@app_commands.command(name='ban', reason=None)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: command() got an unexpected keyword argument 'reason'

The above exception was the direct cause of the following exception:

File "C:\Users\yunus\OneDrive\Desktop\v8 bot\Masaüstü\123\bot.py", line 23, in setup_hook
await bot.load_extension(f'commands.{filename[:-3]}')
File "C:\Users\yunus\OneDrive\Desktop\v8 bot\Masaüstü\123\bot.py", line 27, in <module>
bot.run('4')
discord.ext.commands.errors.ExtensionFailed: Extension 'commands.ban' raised an error: TypeError: command() got an unexpected keyword argument 'reason'

inner barn
#

I told u to remove it

steel dawn
#

I did

#
from discord.ext import commands
from discord import app_commands
import discord
class Moderation(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

@app_commands.command(name='ban', reason=None) 
@app_commands.checks.has_permissions(ban_members=True)
async def ban(self, ctx, member: discord.Member,*, reason=None):
        try:
           await member.ban(reason=reason)
           await discord.Interaction.response.send_message(f'{member} - just got banned for {reason} (so silly goose)')
        except:
          print('im too lazy to continue ur code ,_,') 
       

@app_commands.command(name='unban')
@app_commands.checks.has_permissions(ban_members=True)
async def unban(self, ctx, *, user_id: int):
        try:
            user = await self.bot.fetch_user(user_id)
            await ctx.guild.unban(user)
            await ctx.send(f'{user} Yasağı kaldırıldı')
        except discord.NotFound:
            await ctx.send(f'Kullanıcı ID {user_id} yasaklı kullanıcılar arasında bulunamadı.')
        except discord.Forbidden:
            await ctx.send("Bu kişiyi Yasaklayamazsınız. Yetkim yeterli değil.")
        except discord.HTTPException as e:
            await ctx.send(f"Bir hata oluştu: {str(e)}")

async def setup(bot):
    await bot.add_cog(Moderation(bot))```
inner barn
#

u did not save then

steel dawn
#

I do it via vsc

inner barn
#

control + s

#

do u know python?

#

or u copy paste that code

#

??

steel dawn
#

Yes I know

inner barn
#

i see

steel dawn
#

Exception has occurred: ExtensionFailed
Extension 'commands.ban' raised an error: TypeError: command() got an unexpected keyword argument 'reason'
File "C:\Users\yunus\OneDrive\Desktop\v8 bot\Masaüstü\123\commands\ban.py", line 8, in <module>
@app_commands.command(name='ban', reason=None)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: command() got an unexpected keyword argument 'reason'

The above exception was the direct cause of the following exception:

File "C:\Users\yunus\OneDrive\Desktop\v8 bot\Masaüstü\123\bot.py", line 23, in setup_hook
await bot.load_extension(f'commands.{filename[:-3]}')
File "C:\Users\yunus\OneDrive\Desktop\v8 bot\Masaüstü\123\bot.py", line 27, in <module>
bot.run('4')
discord.ext.commands.errors.ExtensionFailed: Extension 'commands.ban' raised an error: TypeError: command() got an unexpected keyword argument 'reason'

inner barn
#

bruh can U READ

#

@app_commands.command(name='ban', reason=None)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: command() got an unexpected keyword argument 'reason' @app_commands.command(name='ban', reason=None)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: command() got an unexpected keyword argument 'reason' @app_commands.command(name='ban', reason=None)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: command() got an unexpected keyword argument 'reason'

#

Remove reason

steel dawn
#

uh

#

Exception has occurred: ExtensionFailed
Extension 'commands.ban' raised an error: TypeError: parameter 'ctx' is missing a type annotation in callback 'ban'
File "C:\Users\yunus\OneDrive\Desktop\v8 bot\Masaüstü\123\commands\ban.py", line 8, in <module>
@app_commands.command(name='ban')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: parameter 'ctx' is missing a type annotation in callback 'ban'

The above exception was the direct cause of the following exception:

File "C:\Users\yunus\OneDrive\Desktop\v8 bot\Masaüstü\123\bot.py", line 23, in setup_hook
await bot.load_extension(f'commands.{filename[:-3]}')
File "C:\Users\yunus\OneDrive\Desktop\v8 bot\Masaüstü\123\bot.py", line 27, in <module>
bot.run('4')
discord.ext.commands.errors.ExtensionFailed: Extension 'commands.ban' raised an error: TypeError: parameter 'ctx' is missing a type annotation in callback 'ban

#

It's not in right now and there is still an error

inner barn
#

you're trying to use app_commands decorators on a function that's not a method of a class. In your code, ban and unban are standalone functions, but they're being decorated with app_commands.command, which is meant to be used on methods of a class that inherits from commands.Cog.

#

were u from

#

i do you favour and i translate

steel dawn
#

I am from Turkey

inner barn
#

now?

steel dawn
#

I understand

inner barn
#

send me the code then

steel dawn
#
from discord.ext import commands
from discord import app_commands
import discord
class Moderation(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

@app_commands.command(name='ban') 
@app_commands.checks.has_permissions(ban_members=True)
async def ban(self, ctx, member: discord.Member,*, reason=None):
        try:
           await member.ban(reason=reason)
           await discord.Interaction.response.send_message(f'{member} - just got banned for {reason} (so silly goose)')
        except:
          print('im too lazy to continue ur code ,_,') 
       

@app_commands.command(name='unban')
@app_commands.checks.has_permissions(ban_members=True)
async def unban(self, ctx, *, user_id: int):
        try:
            user = await self.bot.fetch_user(user_id)
            await ctx.guild.unban(user)
            await ctx.send(f'{user} Yasağı kaldırıldı')
        except discord.NotFound:
            await ctx.send(f'Kullanıcı ID {user_id} yasaklı kullanıcılar arasında bulunamadı.')
        except discord.Forbidden:
            await ctx.send("Bu kişiyi Yasaklayamazsınız. Yetkim yeterli değil.")
        except discord.HTTPException as e:
            await ctx.send(f"Bir hata oluştu: {str(e)}")

async def setup(bot):
    await bot.add_cog(Moderation(bot))
#
import discord
from discord.ext import commands
import os

intents = discord.Intents.default()
intents.message_content = True

bot = commands.Bot(command_prefix='!', intents=intents)

@bot.event
async def on_ready():
    print(f'Bot olarak giriş yapıldı: {bot.user.name}')
    # Slash komutlarını sadece bir kez senkronize etmek için on_ready olayında çağırıyoruz
    try:
        synced = await bot.tree.sync()
        print(f'Senkronize edilen komut sayısı: {len(synced)}')
    except Exception as e:
        print(f'Senkronizasyon hatası: {e}')

async def setup_hook():
    for filename in os.listdir('./commands'):
        if filename.endswith('.py'):
            await bot.load_extension(f'commands.{filename[:-3]}')

bot.setup_hook = setup_hook

bot.run('')```
inner barn
#

make the class

#
class Moderation(commands.Cog):
    pass
steel dawn
#
from discord.ext import commands
from discord import app_commands
import discord
class Moderation(commands.Cog):
    pass
    def __init__(self, bot):
        self.bot = bot

@app_commands.command(name='ban') 
@app_commands.checks.has_permissions(ban_members=True)
async def ban(self, ctx, member: discord.Member,*, reason=None):
        try:
           await member.ban(reason=reason)
           await discord.Interaction.response.send_message(f'{member} - just got banned for {reason} (so silly goose)')
        except:
          print('im too lazy to continue ur code ,_,') 
       

@app_commands.command(name='unban')
@app_commands.checks.has_permissions(ban_members=True)
async def unban(self, ctx, *, user_id: int):
        try:
            user = await self.bot.fetch_user(user_id)
            await ctx.guild.unban(user)
            await ctx.send(f'{user} Yasağı kaldırıldı')
        except discord.NotFound:
            await ctx.send(f'Kullanıcı ID {user_id} yasaklı kullanıcılar arasında bulunamadı.')
        except discord.Forbidden:
            await ctx.send("Bu kişiyi Yasaklayamazsınız. Yetkim yeterli değil.")
        except discord.HTTPException as e:
            await ctx.send(f"Bir hata oluştu: {str(e)}")

async def setup(bot):
    await bot.add_cog(Moderation(bot))
#

is it true

inner barn
#

No

#

still not

steel dawn
#

So how do I do it?

inner barn
#

encapsulate funcs inside the moderation class that inherints from the command

#

Komutun iyi yazılmış sınıfından dinamik olarak devralınan işlevleri moderasyon özetinin derinliklerinde kapsülledi

#

Ok??

steel dawn
#

How should I do

#

!close

patent lynxBOT
#
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.