#πŸ”’ Can't send messages anymore

53 messages Β· Page 1 of 1 (latest)

plucky delta
#

hello fam, when I send a basic message i get the error here down.
But not every time, sometimes it works. Only on spider, when I launch it on my putty session, it doesn't even give any error message back. Help me please

||[2024-08-06 21:04:52] [INFO ] discord.client: logging in using static token
[2024-08-06 21:04:53] [INFO ] discord.gateway: Shard ID None has connected to Gateway (Session ID: d7292d7955f25c5c53d1519ea5dc373e).

Output from spyder call 'get_namespace_view':
Task exception was never retrieved
future: <Task finished name='discord.py: on_ready' coro=<Client._run_event() done, defined at C||

frank sundialBOT
#

@plucky delta

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.

plucky delta
#

if i add +" " to my message, it sends it once without error, but then sends always the error, even if i restart kernel

#

I get this now on putty

idle raptor
#

Start off with your complete code

#

!paste

frank sundialBOT
#
Pasting large amounts of code

If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.

plucky delta
#
import discord
import nest_asyncio
import sys

nest_asyncio.apply()
intents = discord.Intents.default()
dclient = discord.Client(intents=intents)

w = 0

send = "yes"

@dclient.event
async def on_ready():
    message = "z"
    user = await dclient.fetch_user(190799007331778560) # moi
    await user.send(message)
    sys.exit()

if send != "no":
    dclient.run('----------------------')```
sinful cosmos
#

dclient

#

why "d"?

plucky delta
#

bc I run binance as the same time and it already uses client

sinful cosmos
#

ah, fair

plucky delta
#

I have this code for 6 months now, and I didn't change anything in the send message part

#

So I made a code with only send message, and I still get the error

#

It worked until today πŸ˜†

sinful cosmos
#

you're sending the message to a specific user through dms, correct?

plucky delta
#

yes

#

even with the error, it sends the message when I use spyder

#

but with putty, it doesn't (or sometimes does) gives error, but never sends message

sinful cosmos
#

hm

#

the only thing I can suggest, at the moment, is you use the logging package to try and find where and what is actually causing the issue

#

pretty much just do logging.debug (assuming you've imported the package and setup the basicConfig) after your statements
i.e:

@dclient.event
async def on_ready():
  logging.debug("Entering on_ready")
  message = "z"
  user = await dclient.fetch_user(190799007331778560) # moi
  logging.debug(f"Fetched user: {user}")
  await user.send(message)
  logging.debug("Message sent successfully")
  sys.exit()
plucky delta
#

i'll try thanks

#

I sent the message without error

#

so I closed the console and tried in a new, and get the error message again

sinful cosmos
#

send your error

plucky delta
sinful cosmos
#

try it without the sys.exit()

plucky delta
#

I don't get any error but my console run to infinite

sinful cosmos
#

alright, but does it send the message?

plucky delta
#

yes

#

but my putty program runs once every minutes, it will crash in 10 minutes if the running programs accumulate

sinful cosmos
#

you should be able to use CTRL + C inside of your terminal to stop the bot

plucky delta
#

it runs 24/7 sadly

sinful cosmos
#

hm

#

idk how to help with that, as I don't use, nor have I ever heard of putty

plucky delta
#

it's a ubuntu virtual computer

#

i use it for the crontab

misty granite
#

Maybe it's because your bot is still running when you exit? Try calling await dclient.close() before the exit.

plucky delta
#

oh boy it works

#

I still have to close the console bc doesn't run any code after that but I don't get any error

#

I still get that on ubuntu, but it sent the message

#

thank you very much guys :)

#

I keep the thread open in case you know what to answer to this ↑

misty granite
#

Honestly, I don't have another suggestion at the moment.
The traceback suggests it might have something to do with nest_asyncio. Maybe it doesn't like you exiting when another task may still be running?
You could make sure there are no other tasks running when you exit, or maybe try removing nest_asyncio and see if that fixes your problem?

plucky delta
#

I don't know how to send a message without asyncio actually

#

but np it's ok like that I guess lmao

frank sundialBOT
#
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.