#đź”’ Help!!!

159 messages · Page 1 of 1 (latest)

dull pendantBOT
#

@gaunt lotus

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.

gaunt lotus
#

Here is the link to the code

#

It was too long too paste

unborn ginkgo
#

What even is the problem?

obsidian crescent
#

Help with what exactly...

unborn ginkgo
#

and I think you have some unnecessary lines there

gaunt lotus
#

everytime i run it the counting system is working and also the welcomer but nothing else

#

chatgpt says because of the on_message

#

But idk

tawdry agate
#

and do not trust chatgpt cuz its outdated

unborn ginkgo
#

Also I would remove the empty duplicated on_message if I were you

tawdry agate
tender trout
unborn ginkgo
#

If the code looks clean it's easier to spot mistakes genuinely 🙂

tawdry agate
gaunt lotus
#

You mean the 1x in the count system?

tawdry agate
#

I am not sure why its not working because last time I read the discord.py code, I saw that it appends events and not overwrite them

gaunt lotus
#

ther?

tawdry agate
#

yes

gaunt lotus
#

and change it with bot.process_command(message) that

tawdry agate
#

I will check if the function name is correct

#

yes its bot.process_commands with an s

#

and replace the bot with the actual bot veriable name

tacit estuary
gaunt lotus
#

ik

#

PS Z:\Lukas\Studio Code\DeserrtTemple Bot> python main.py
File "Z:\Lukas\Studio Code\DeserrtTemple Bot\main.py", line 133
async def bot.process_commands(message):
^
SyntaxError: expected '('

tawdry agate
gaunt lotus
#

idk

#

???

tawdry agate
gaunt lotus
tawdry agate
#

at the end

gaunt lotus
#

oh hahha

tawdry agate
# gaunt lotus

revert the changes it and put it at the end of the function

gaunt lotus
#

im dumb

tawdry agate
gaunt lotus
#

yould u write the full line

#

pls

#

im toooooo dumb

tawdry agate
#

hmm.. sure but you should know why I applied those changes

gaunt lotus
#

bc i did i two times?

#

no?

tawdry agate
#

delete this


@client.event
async def on_message(message):
    if message.author.bot:
        return

    # Hier kannst du weitere Logik für die Bearbeitung von Nachrichten in Ticket-Kanälen hinzufügen

    await client.process_commands(message)

as its getting overwritten anyways

gaunt lotus
#

and now?

tawdry agate
gaunt lotus
#

there is still this

tawdry agate
gaunt lotus
tawdry agate
#

may I ask why not make this a actual command?

        if 
message.content.startswith('!count'):
            await message.channel.send(f'Aktueller Zählerwert: {count}')

        # Prüfe, ob die Nachricht den erwarteten Zählerwert enthält
        try:
            user_count = int(message.content)
        except ValueError:
            return  # Ignoriere Nachrichten, die keine Zahl enthalten

        if user_count == count + 1:
            count = user_count
            await message.add_reaction('✅')  # Bestätige die korrekte Nachricht
        else:
            await message.add_reaction('❌')  # Weise auf einen Fehler hin
            await asyncio.sleep(5)
            await message.delete()  
gaunt lotus
#

idk what u mean

#

im bad at english

#

bc im german

tawdry agate
#

oh I see

#

why use if?

if message.content.startswith('!count'):

when you can do

@client.command()
async def count(ctx):
  ... # code here
#

here how I will do it

@client.command()
async def count(ctx):
    await message.channel.send(f'Aktueller Zählerwert: {count}')

@client.event
async def on_message(message):
    global count  # Wir verwenden die globale Variable 'count'

    if message.author.bot:
        return  # Ignoriere Nachrichten vom Bot selbst

    if message.channel.id == allowed_channel_id:
        # Prüfe, ob die Nachricht den erwarteten Zählerwert enthält
        try:
            user_count = int(message.content)
        except ValueError:
            return  # Ignoriere Nachrichten, die keine Zahl enthalten

        if user_count == count + 1:
            count = user_count
            await message.add_reaction('✅')  # Bestätige die korrekte Nachricht
        else:
            await message.add_reaction('❌')  # Weise auf einen Fehler hin
            await asyncio.sleep(5)
            await message.delete()
        return # return to stop it from reaching to process_commands
    



    await client.process_commands(message) # process commands
#

@gaunt lotus

gaunt lotus
#

yeah

#

and now it should work?

tawdry agate
tawdry agate
gaunt lotus
#

Its still not working

#

@tawdry agate

#

ig the problem ist, that count = 0 is never said

#

Why is there a line said which doesnt exist?

tawdry agate
#

it will been better if you sent the error as text

gaunt lotus
#

How?

#

oh haha

#

wait

tawdry agate
#

oh yes I see why

#

the async def count is overwriting the count

#

in basic english, the function count is replacing the count number

gaunt lotus
#

?

#

and what should i do? rename?

unborn ginkgo
#

You'd need to rename the function yes

#

or the count number

gaunt lotus
#

to eg count1

tawdry agate
#

should work

gaunt lotus
#

its still not working

unborn ginkgo
#

have you defined count as a global in your code?

gaunt lotus
#

wait

unborn ginkgo
#

or where is it defined

gaunt lotus
#

yeah

#

global count # Wir verwenden die globale Variable 'count'

woeful heath
#

that's not defining the variable. it's just telling python to look for a global variable named count.. you'll still get a NameError if you never defined it (by assigning a value somewhere in the global scope)

gaunt lotus
gaunt lotus
tawdry agate
gaunt lotus
#

no hhaha

#

lol

unborn ginkgo
#

then that wont work

tawdry agate
#

anything that isn't define, you will need to define it

gaunt lotus
#

should i write count_ or count = 0

unborn ginkgo
#

count = 0

#

because you just used count_ for a function

tawdry agate
gaunt lotus
#

so the command is !count_

unborn ginkgo
#

no, the command is !count

#

since you've changed the name

#

Please always make sure to know what you are pasting in from others before doing so 🙂

tawdry agate
gaunt lotus
#

yeah haha

#

now is the counting system working but !count is still not working

unborn ginkgo
#

Also another tip, please provide more Information, just saying "is not working" is not much of detail, there could be 1000 reasons for this 🙂

gaunt lotus
#

the bot isnt answering !count

unborn ginkgo
#

Does it say anything in the console? Have you tried debugging the code on what maybe doesn't work?

gaunt lotus
#

PS Z:\Lukas\Studio Code\DeserrtTemple Bot> python main.py
2024-02-17 20:31:08 INFO discord.client logging in using static token
2024-02-17 20:31:09 INFO discord.gateway Shard ID None has connected to Gateway (Session ID: be1a80016540fdf46c7c4bb08020dd8f).
Der Bot ist online!
2024-02-17 20:31:38 ERROR discord.ext.commands.bot Ignoring exception in command count
Traceback (most recent call last):
File "C:\Users\Tanja und Jochen\AppData\Local\Programs\Python\Python312\Lib\site-packages\discord\ext\commands\core.py", line 235, in wrapped
ret = await coro(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "Z:\Lukas\Studio Code\DeserrtTemple Bot\main.py", line 129, in count_
await message.channel.send(f'Aktueller Zählerwert: {count}')
^^^^^^^
NameError: name 'message' is not defined. Did you mean: 'on_message'?

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

Traceback (most recent call last):
File "C:\Users\Tanja und Jochen\AppData\Local\Programs\Python\Python312\Lib\site-packages\discord\ext\commands\bot.py", line 1350, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\Tanja und Jochen\AppData\Local\Programs\Python\Python312\Lib\site-packages\discord\ext\commands\core.py", line 1029, in invoke
await injected(*ctx.args, **ctx.kwargs) # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Tanja und Jochen\AppData\Local\Programs\Python\Python312\Lib\site-packages\discord\ext\commands\core.py", line 244, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: NameError: name 'message' is not defined
2024-02-17 20:31:42 ERROR discord.ext.commands.bot Ignoring exception in command None

#

thats in the console

#

should i say on_message?

unborn ginkgo
#

You didn't define that, in this case you need to do ctx.channel.send instead of message.channel.send

gaunt lotus
#

not message?

unborn ginkgo
tawdry agate
gaunt lotus
#

how can i do this?

unborn ginkgo
#

three backticks ` at the start and end

gaunt lotus
#

the terminal say instead is false

tawdry agate
dull pendantBOT
#
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.

gaunt lotus
unborn ginkgo
#

Why did you put instead there?

gaunt lotus
#

await ctx.channel.send instead(f'Aktueller Zählerwert: {count}')

#

idk?

tawdry agate
#

instead is not a thing

unborn ginkgo
gaunt lotus
#

idk how it got there lol

unborn ginkgo
#

I thought both was valid

tawdry agate
unborn ginkgo
gaunt lotus
#

GUYS ITS FUCKING WORKING (sry)

#

thank u so much

#

thaaaaaaank uuuuuu

#

<3

tawdry agate
gaunt lotus
#

a half our

unborn ginkgo
#

No problem

gaunt lotus
#

broo

#

ur the best

tawdry agate
unborn ginkgo
tawdry agate
#

@gaunt lotus if you think your problem has been solved, you can do !close to close the thread

gaunt lotus
#

<3

#

!close

dull pendantBOT
#
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.