OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Discord.py every command doesn't work only on_message(message):

  • Thread starter Thread starter Kamil Konieczny
  • Start date Start date
K

Kamil Konieczny

Guest
I know discord.py is kinda old but like 2 years ago i discovered this and decided to try code, kinda lost it and month ago retry coding

So i have this strange error beacose while i was codding tree comands i delete something and my commands stopped working

Spent 2 days to find solution but still the same

Here is part of code:

Main.py

Code:
`import datetime
import discord
from discord.ext import commands
from discord.ext.commands import has_permissions, MissingPermissions

from client import client
from fun import ocena
from moderation import delete, usun_kanal, dodaj_kanal
from spaming import ghost, spam, stop, spam_error


@client.command()
async def pfp(ctx, *, avamember: str = None):
    if avamember is None:
        await ctx.send("Musisz oznaczyć użytkownika!")
        return

    try:
        avamember = await commands.MemberConverter().convert(ctx, avamember)
    except commands.MemberNotFound:
        await ctx.send("Nie mogłem znaleźć tego użytkownika!")
        return

    user_avatar_url = avamember.display_avatar.url
    await ctx.send(f"**Awatar użytkownika** {avamember.name}: {user_avatar_url}")


@client.command()
async def ocenka(ctx):
.......

@client.event
async def on_command_error(ctx, error):
    if ctx.message.content.count('.') <= 1:
        if isinstance(error, commands.CommandNotFound):
            await ctx.send("Podano złą komende! ⚠️")


@client.event
async def on_message(message):
    if client.user.mentioned_in(message):
        await message.channel.send("Witaj! Aby zobaczyć liste moich komend wpisz `.help `! ")


@client.event
async def on_ready():
    await client.change_presence(status=discord.Status.idle,
                                 activity=discord.Game(name="Wpisz .help by zobaczyć co mogę dla ciebie zrobić!"))
    print('------------------------------')
    print('Pomyślnie zalogowano jako:')
    print("Nazwa bota:", client.user.name)
    print("Id bota:", client.user.id)
    print("Bot został uruchomiony", datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
    print('------------------------------')


client.run(`yk`)

client.py

Code:
import discord
from discord.ext import commands

intents = discord.Intents.all()
client = commands.Bot(command_prefix='.',intents=intents)
tree = client.tree

client.remove_command('help')

Rest of files are commands but pattern is basicly the same from command import command

@client.command() async def command(ctx): await command(ctx)

I have twice @client.command() for command First in main.py :

Code:
@client.command
async def delete(ctx, name):
    await delete(ctx, name)

Second in command.py:

Code:
@client.command()
@has_permissions(manage_messages=True)
async def delete(ctx, count):
    try:
        count = int(count)
        if (count < 0):
            await ctx.send("wrong number")
            return
    except ValueError:
        await ctx.send("error")
    else:
        await ctx.send(f"{count} messages")
        deleted_messages = await ctx.channel.purge(limit=count + 1)

I save this "method" or "schema" on some old youtube tutorial so i decided to do the same

ready for down arrows 😔
<p>I know discord.py is kinda old but like 2 years ago i discovered this and decided to try code, kinda lost it and month ago retry coding</p>
<p>So i have this strange error beacose while i was codding tree comands i delete something and my commands stopped working</p>
<p>Spent 2 days to find solution but still the same</p>
<p>Here is part of code:</p>
<p>Main.py</p>
<pre><code>`import datetime
import discord
from discord.ext import commands
from discord.ext.commands import has_permissions, MissingPermissions

from client import client
from fun import ocena
from moderation import delete, usun_kanal, dodaj_kanal
from spaming import ghost, spam, stop, spam_error


@client.command()
async def pfp(ctx, *, avamember: str = None):
if avamember is None:
await ctx.send("Musisz oznaczyć użytkownika!")
return

try:
avamember = await commands.MemberConverter().convert(ctx, avamember)
except commands.MemberNotFound:
await ctx.send("Nie mogłem znaleźć tego użytkownika!")
return

user_avatar_url = avamember.display_avatar.url
await ctx.send(f"**Awatar użytkownika** {avamember.name}: {user_avatar_url}")


@client.command()
async def ocenka(ctx):
.......

@client.event
async def on_command_error(ctx, error):
if ctx.message.content.count('.') <= 1:
if isinstance(error, commands.CommandNotFound):
await ctx.send("Podano złą komende! ⚠️")


@client.event
async def on_message(message):
if client.user.mentioned_in(message):
await message.channel.send("Witaj! Aby zobaczyć liste moich komend wpisz `.help `! ")


@client.event
async def on_ready():
await client.change_presence(status=discord.Status.idle,
activity=discord.Game(name="Wpisz .help by zobaczyć co mogę dla ciebie zrobić!"))
print('------------------------------')
print('Pomyślnie zalogowano jako:')
print("Nazwa bota:", client.user.name)
print("Id bota:", client.user.id)
print("Bot został uruchomiony", datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
print('------------------------------')


client.run(`yk`)
</code></pre>
<p>client.py</p>
<pre><code>import discord
from discord.ext import commands

intents = discord.Intents.all()
client = commands.Bot(command_prefix='.',intents=intents)
tree = client.tree

client.remove_command('help')

</code></pre>
<p>Rest of files are commands but pattern is basicly the same
from command import command</p>
<p>@client.command()
async def command(ctx):
await command(ctx)</p>
<p>I have twice @client.command() for command
First in main.py :</p>
<pre><code>@client.command
async def delete(ctx, name):
await delete(ctx, name)
</code></pre>
<p>Second in command.py:</p>
<pre><code>@client.command()
@has_permissions(manage_messages=True)
async def delete(ctx, count):
try:
count = int(count)
if (count < 0):
await ctx.send("wrong number")
return
except ValueError:
await ctx.send("error")
else:
await ctx.send(f"{count} messages")
deleted_messages = await ctx.channel.purge(limit=count + 1)

</code></pre>
<p>I save this "method" or "schema" on some old youtube tutorial so i decided to do the same</p>
<p>ready for down arrows 😔</p>
 

Latest posts

Top