#🔒 does not see the existing command

228 messages · Page 1 of 1 (latest)

glass quartzBOT
#

@tropic sandal

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.

tropic sandal
#
import discord
from discord.ext import commands

# Intents'leri etkinleştirme
intents = discord.Intents.default()
intents.members = True
'intents.message_content = True

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

# Komutları yükleme fonksiyonu
def load_commands(bot):
    for filename in os.listdir('commands'):
        if filename.endswith('.py'):
            bot.load_extension(f'commands.{filename[:-3]}')

@bot.event
async def on_ready():
    print(f'{bot.user} olarak giriş yaptı!')
    load_commands(bot)



bot.run("token")```
#

class TekmilCog(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

    @commands.command(name='tekmil')
    async def tekmil(self, ctx):
        # Komutun çağrıldığı kanalı bulun
        channel = ctx.channel
        # Kanala istediğiniz mesajı gönderin
        await channel.send('Tekmil mesajınızı buraya yazın!')

def setup(bot):
    bot.add_cog(TekmilCog(bot)```
#

2024-02-21 21:33:13 ERROR discord.ext.commands.bot Ignoring exception in command None
discord.ext.commands.errors.CommandNotFound: Command "tekmil" is not found

elfin ibex
#
  1. setup() is now a coroutine, maybe try to set to async def
  2. Are you sure the extension was successfully loaded?
  3. Do you have any other errors in your log records?
tropic sandal
#

2024-02-21 21:32:42 INFO discord.client logging in using static token
2024-02-21 21:32:44 INFO discord.gateway Shard ID None has connected to Gateway (Session ID: 9c99b3d3459d37fb5d7a7ebef49f25ab).

tropic sandal
#
  1. How can I do technique?
elfin ibex
#

Make it asynchronous.

#

like async def

tropic sandal
#

main.py Should I write to the file def setup(bot):

elfin ibex
#

Eh.

tropic sandal
#

def setup(bot):

#

no

elfin ibex
#

in main.py, you will have to load the extension

tropic sandal
#

RuntimeWarning: Enable tracemalloc to get the object allocation traceback
2024-02-21 21:46:53 ERROR discord.ext.commands.bot Ignoring exception in command None
discord.ext.commands.errors.CommandNotFound: Command "tekmil" is not found

elfin ibex
elfin ibex
tropic sandal
#

from discord.ext import commands

class TekmilCog(commands.Cog):
def init(self, bot):
self.bot = bot

@commands.command(name='tekmil')
async def tekmil(self, ctx):
    # Komutun çağrıldığı kanalı bulun
    channel = ctx.channel
    # Kanala istediğiniz mesajı gönderin
    await channel.send('Tekmil mesajınızı buraya yazın!')

def setup(bot):
bot.add_cog(TekmilCog(bot))

elfin ibex
#

I get it I get it. Can you please make setup(bot) -> async def setup(bot) (make it asynchronous) as a start?

tropic sandal
elfin ibex
# tropic sandal where do i write this

Make the three functions asynchronous:
-> def load_commands(bot) -> async def load_command(bot)
-> def setup(bot) -> async def setup(bot)
-> bot.add_cog(TekmilCog(bot)) -> await bot.add_cog(TekmilCog(bot))
-> In on_ready load_commands(bot) -> await load_commands(bot)

#

Do you acknowledge what a coroutine is?

elfin ibex
#

In case you haven't known what asynchronous programming is.

tropic sandal
#

[{
"resource": "/c:/Users/yunus/OneDrive/Desktop/v8 bot/Masaüstü/tat/main.py",
"owner": "generated_diagnostic_collection_name#0",
"code": {
"value": "F821",
"target": {
"$mid": 1,
"path": "/ruff/rules/undefined-name",
"scheme": "https",
"authority": "docs.astral.sh"
}
},
"severity": 8,
"message": "Undefined name load_commands",
"source": "Ruff",
"startLineNumber": 21,
"startColumn": 11,
"endLineNumber": 21,
"endColumn": 24
}]

#

error

elfin ibex
#

Change def load_commands -> async def load_commands

tropic sandal
#

yes,

elfin ibex
#

And in on_ready await the load_commands function

tropic sandal
#

[{
"resource": "/c:/Users/yunus/OneDrive/Desktop/v8 bot/Masaüstü/tat/main.py",
"owner": "generated_diagnostic_collection_name#0",
"code": {
"value": "E999",
"target": {
"$mid": 1,
"path": "/ruff/rules/syntax-error",
"scheme": "https",
"authority": "docs.astral.sh"
}
},
"severity": 8,
"message": "SyntaxError: Unexpected token Newline",
"source": "Ruff",
"startLineNumber": 21,
"startColumn": 30,
"endLineNumber": 21,
"endColumn": 31
}]

#

[{
"resource": "/c:/Users/yunus/OneDrive/Desktop/v8 bot/Masaüstü/tat/main.py",
"owner": "generated_diagnostic_collection_name#2",
"severity": 8,
"message": "Expected ":"",
"source": "Pylance",
"startLineNumber": 21,
"startColumn": 30,
"endLineNumber": 22,
"endColumn": 1
}]

elfin ibex
#

Show me code

#

There is some syntax error

tropic sandal
#

import os
import discord
from discord.ext import commands

Intents'leri etkinleştirme

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

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

Komutları yükleme fonksiyonu

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

@bot.event
async def on_ready():
print(f'{bot.user} olarak giriş yaptı!')
async def load_commands():

bot.run("...")

tropic sandal
elfin ibex
#

Oh

elfin ibex
#

make it await load_commands(bot)

#

Basically on_ready is like you did before but add await before load_commands(bot)

#

If this makes sense

#

@tropic sandal

tropic sandal
#

aror

#

error

elfin ibex
#

well you switched things

#

async def load_commands(): should be in place of await load_commands(bot)

#

switch places

#

also

#

increase indentation of for filename in ... thing and the two lines after it

#

I also want to note that this is basic python which you should be aware of it already.

tropic sandal
#

where do I write this?

#

await load_commands(bot)

#

How much should I get it?

elfin ibex
#

No, I wasn't talking about that part.

#

Sorry, sir, I think I am not explaining it enough.

#

Additionally, you will need to learn more Python basics before you dive into intermediate/advanced-level projects like discord.py

#

I am not judging.

tropic sandal
#

They teach at school

elfin ibex
#

That's nice. Well, I will try to help you

#

Try to catch up

tropic sandal
#

Can you write the code for me? Don't write if you want but

tropic sandal
elfin ibex
#

At least you were learning something, right?

tropic sandal
elfin ibex
#

Cool.

#

Now, let's begin.

#

Basically, this is a false syntax:

await load_commands()
#

I mean

#

In line 9

#

It has a red underscore

tropic sandal
#

9th line is empty

elfin ibex
#

oh then it's line 11?

tropic sandal
#

There is no red line underneath

#

14 and 24 line error

elfin ibex
#

Oh

#

Switch these

#

like

#

There is:

print(...)
async def load_commands():

and:

await load_commands()
for filename in ...:
  ...
tropic sandal
elfin ibex
#

Add spaces before it

tropic sandal
elfin ibex
#

change this to async def load_commands(bot):

#

literally

#

change it in a literal manner

tropic sandal
#

Now the for variable gives an error

elfin ibex
#

Show me

tropic sandal
elfin ibex
#

Great so far.

#

Now

#

At line 4

#

Add four spaces

#

Before the word for

#

Done?

tropic sandal
#

4 empty, no continuation, gives error

elfin ibex
#

show

tropic sandal
elfin ibex
#

Well, remove the word "for"

#

I was talking about line 14, I said add four spaces (click on space four times) while the cursor should be targeted at before for

#

So basically for filename in -> for filename in

#

Like that

tropic sandal
#

okey

#

bot run error

#

[{
"resource": "/c:/Users/yunus/OneDrive/Desktop/v8 bot/Masaüstü/tat/main.py",
"owner": "generated_diagnostic_collection_name#0",
"code": {
"value": "E999",
"target": {
"$mid": 1,
"path": "/ruff/rules/syntax-error",
"scheme": "https",
"authority": "docs.astral.sh"
}
},
"severity": 8,
"message": "SyntaxError: Expected 'Indent', but got Dedent",
"source": "Ruff",
"startLineNumber": 24,
"startColumn": 1,
"endLineNumber": 24,
"endColumn": 2
}]

elfin ibex
#

Show me code

tropic sandal
elfin ibex
#

Yes

#

16th line

#

Make it await load_commands(bot)

#

Also

#

Wait

elfin ibex
#

Sorry

#

In 21st line

tropic sandal
#

no problem

elfin ibex
#

Also another chage

#

change

#

In 16th line you can see bot.load_extension so add await before it to be like await bot.load_extension

tropic sandal
#

await load_commands(bot)

elfin ibex
tropic sandal
#

ERROR discord.client Ignoring exception in on_ready

elfin ibex
#

Show me

tropic sandal
elfin ibex
#

You did bot.load_extension to await bot.load_extension right?

tropic sandal
#

yes

elfin ibex
#

Issue's from commands/alim_duyuru

#

Open it

#

Leave main.py untouched since it's working well.

tropic sandal
#

import discord
from discord.ext import commands

class DuyuruCog(commands.Cog):
def init(self, bot):
self.bot = bot

@commands.command(name='bransduyuru')
async def bransduyuru(self, ctx, *, message):
    # Duyuruların yapılacağı kanalı belirleyin (örneğin, burada kanalın adı "duyuru-kanalı" olarak varsayıldı)
    channel = discord.utils.get(ctx.guild.channels, name='duyuru-kanalı')
    
    # Eğer belirlenen kanal bulunamazsa uyarı ver
    if not channel:
        await ctx.send("Duyuruların gönderileceği kanal bulunamadı.")
        return
    
    # Bot kendi mesajını oluşturup link ekleyerek gönder
    bot_message = f"{message}\n\nBranş alımı duyurusu yap. Oyun linki: https://orneklink.com"
    await channel.send(bot_message)
    await ctx.send('Branş alımı duyurusu yapıldı!')

def setup(bot):
bot.add_cog(DuyuruCog(bot))

elfin ibex
#

Okay

#

Put it in brackets

#

!code

glass quartzBOT
#
Formatting code on Discord

Here's how to format Python code on Discord:

```py
print('Hello world!')
```

These are backticks, not quotes. Check this out if you can't find the backtick key.

For long code samples, you can use our pastebin.

tropic sandal
#

How will I share?

elfin ibex
#

Add ```py then a newline, then paste your code, then other \` and send it

#

sir

tropic sandal
#
from discord.ext import commands

class DuyuruCog(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

    @commands.command(name='bransduyuru')
    async def bransduyuru(self, ctx, *, message):
        # Duyuruların yapılacağı kanalı belirleyin (örneğin, burada kanalın adı "duyuru-kanalı" olarak varsayıldı)
        channel = discord.utils.get(ctx.guild.channels, name='duyuru-kanalı')
        
        # Eğer belirlenen kanal bulunamazsa uyarı ver
        if not channel:
            await ctx.send("Duyuruların gönderileceği kanal bulunamadı.")
            return
        
        # Bot kendi mesajını oluşturup link ekleyerek gönder
        bot_message = f"{message}\n\nBranş alımı duyurusu yap. Oyun linki: https://orneklink.com"
        await channel.send(bot_message)
        await ctx.send('Branş alımı duyurusu yapıldı!')

def setup(bot):
    bot.add_cog(DuyuruCog(bot))```
tropic sandal
elfin ibex
#

Oh

tropic sandal
#

Is it like this?

elfin ibex
#

Yes

elfin ibex
#

also add await before bot.add_cog

#

It will fix it

tropic sandal
#

def init?

elfin ibex
#

noo

#

last two lines

#

def setup(bot): -> async def setup(bot):
bot.add_cog -> await bot.add_cog

#

I also want to note that, since you learn Python at school, you can self learn too

#

It will help

tropic sandal
#

I already tried to bot it to learn on my own.

elfin ibex
#

Okay

tropic sandal
#

I already did it but it still gives me

elfin ibex
#

Is it same file we were just updating?

tropic sandal
#

yes

elfin ibex
#

It says you loaded it twice

#

Show me setup() function

#

It implies that you loaded it somewhere else in the project.

#

Oh, I know why.

#

Ok?

#

Done?

tropic sandal
elfin ibex
#

You have the same cog name in two files

#

You have two options to fix that:

  • 1 > Don't make them similar. One option is to rename one of them to some other name.
  • 2 > You can make the two commands in one cog, in one file, and maybe delete the another.
#

First solution is maybe easier

tropic sandal
#

It resembles my "duyuru" part

elfin ibex
#

Well, you can't make two cogs with same name.

tropic sandal
#

discord.ext.commands.errors.CommandNotFound: Command "egitimduyuru" is not found

#

I chose path 2

elfin ibex
#

Okay

elfin ibex
tropic sandal
elfin ibex
#

Put indentation

#

Spacss

tropic sandal
#

how?

elfin ibex
#

Before 22nd and 23rd lines.

#

Four spaces

#

Before each one

tropic sandal
#

class DuyuruCog(commands.Cog):
def init(self, bot):
self.bot = bot

#

?

elfin ibex
#

No

#

22nd and 23rd

#

Wait

#

I mean

#

23rd and 24th

#

Sorry lol

#

You can see them not sync with indentation

tropic sandal
#

How do I indent?

elfin ibex
#

Click on space

#

Four times

#

Before each line

#

Like we did before, remember?

#

smth -> smth

#

for example ^

tropic sandal
tropic sandal
elfin ibex
#

That's not something in code

#

You should do something like !egitimduyuru your_message

#

You haven't

tropic sandal
#

thank you

elfin ibex
#

Anytime, sir.

#

I want to note that, if you would ever like to close any thread (not just this one) in this server you can easily do !close.

tropic sandal
#

!close

glass quartzBOT
#
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.