#🔒 error
63 messages · Page 1 of 1 (latest)
@steel dawn
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.
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'
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
Which file should I assign?
.
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('
')````
the issue is that the reason parameter should be defined within the function, not as a parameter of the @app_commands.command decorator.
How do I do it? I just started using discord.py.
docs
?
and .
remove the field in first decorator
I don't know exactly what this means in decorator in my own language.
@app_commands.command(name='unban', reason=None)
to
@app_commands.command(name='unban')
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'
I told u to remove it
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))```
u did not save then
I do it via vsc
Yes I know
i see
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'
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
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
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
I am from Turkey
now?
I understand
send me the code then
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('')```
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
So how do I do it?
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??
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.