#๐Ÿ”’ How to send "create message" events to discord websocket as JSON?

43 messages ยท Page 1 of 1 (latest)

slim pine
#

Is there any solution, please help?

tough bronzeBOT
#

@slim pine

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.

remote cobalt
#

send to discord websocket? are you trying to create your own discord bot framework?

slim pine
#

want framework? No, I experiment with the discord api thats it and understand it:

#

while True:
events = receive_data(ws)
print(events)
if events["t"] == "READY":
print("Bot has started.....")

tough bronzeBOT
#

Hey @slim pine!

It looks like you're trying to paste code into this channel.

Discord has support for Markdown, which allows you to post code with full syntax highlighting. Please use these whenever you paste code, as this helps improve the legibility and makes it easier for us to help you.

To do this, use the following method:
```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
You can **edit your original message** to correct your code block.
slim pine
#

when event["t"] == "MESSAGE_CREATE" i want to send a message

#

like a reply

#

I tried with message = {"content" : "Hello world"} but when I send it , the websocket closes

#

send_data(ws, message)

remote cobalt
#

that is fairly advanced - I would strongly recommend using a framework like discord.py or hikari instead of implementing it yourself

alternatively, you can try looking at their source code to see how they implement it and use that as a base for your own project

slim pine
#

I receive events in the while loop

#

when I update channel or send messages on my test discord

#

but I dont want to receive always I also want to send

open wadi
slim pine
#

ah ok, yeah that I have done yesterday with the requets library

#

as a test

#

so you mean the websocket doesnt want any inputs?

#

it gives me inputs to work with?

#

I receive json data that I then convert into a python obj

open wadi
#

MESSAGE_CREATE is a Receive-only event. You can't send those.

slim pine
#

ok ok yeah your right. I see it. Than I must work with POST DELETE GET PATCH PUT

open wadi
#

Yeah. The docs are pretty clear on what you can do with the gateway vs the REST API.

slim pine
#

I think simply said when getaway event is qual to an event like MESSAGE_CREATE I can extract some datas store it in variables and fire it with the right link with requests.get post delete ....

slim pine
#

would you approve this?

open wadi
slim pine
#

yeah

#

the message is displayed multiple times is there a reason?

open wadi
#

That's why people check if their messages weren't sent by their own bot.

slim pine
#

ah ok wait i send you a screenshot

#

i type s and then this

open wadi
#

Yeah, that's what I mentioned earlier. You'd handle it like you typically would when doing a Discord bot (here's the message object for reference).

I will acknowledge etrotta's previous mention that the Discord API can get fairly complex and you should look into the documentation which tends to be pretty clear on most topics. You can also refer to other existing frameworks and there's also the Discord Developers server if you have any doubts (we have a thread too: https://discord.com/channels/267624335836053506/965291516031549500)

slim pine
#

ah thanks I dont want to build a framework or something else I want to just experiment with it

#

and btw it is good to know what discord py makes under the hood @open wadi

#

thanks a lot guys

#

my todays accomplishements are connect to the getaway , sending heartbeats in an other thread , send the identifier and receiving events

open wadi
tough bronzeBOT
#
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.