Is it possible to fetch recent Discord messages without using a Discord bot?

I’ve made a program that can send Discord messages without logging in. But now I’m having trouble figuring out how to receive messages. I don’t want to deal with the confusing aspects of the Discord.py bot, so I’m looking for an alternative way to fetch messages. Could someone please explain how I might achieve this without relying on Discord.py? If it’s necessary to use it in some form, a clear and simple explanation would be really appreciated.

Here’s a modified code snippet to illustrate what I’ve tried so far:

import requests
import tkinter as tk

def fetch_messages():
    # Placeholder for receiving messages
    pass

def send_message():
    channel_url = 'https://discord.com/api/channels/CHANNEL_ID/messages'
    headers = {'Authorization': 'Bot TOKEN'}
    content = {'content': 'Hello, Discord!'}
    response = requests.post(channel_url, headers=headers, json=content)
    if response.status_code == 200:
        print('Message sent successfully')
    else:
        print('Failed to send message')

root = tk.Tk()
root.title('Discord Messenger')

send_button = tk.Button(root, text='Send Message', command=send_message)
send_button.pack()

root.mainloop()

How can I add the capability to receive messages to the program? Thanks for any help!

I’ve been in your shoes, trying to navigate Discord’s API without using a bot. It’s tricky, but there’s a way. I ended up using Discord’s websocket gateway for real-time message fetching. It’s more complex than REST API calls, but it’s efficient and doesn’t violate ToS as badly as using a user token.

Here’s the gist: You establish a websocket connection to Discord’s gateway, authenticate, and then listen for message events. You’ll need to handle heartbeats and other gateway events, which can be a bit of a learning curve.

I found the ‘websockets’ library in Python helpful for this. It took some trial and error, but once set up, it works smoothly. Just be cautious with your implementation to avoid rate limits or suspicious activity flags.

Remember, while this method works, it’s in a grey area. If you’re building something long-term or public, consider biting the bullet and learning Discord.py. It’s complex at first, but it’ll save you headaches down the line.

hey, i feel ya on the discord.py struggle. have u looked into using the discord API directly? it’s a bit of a pain, but u can make HTTP requests to fetch messages. u’ll need ur user token (keep it secret!) and the channel ID. then u can use the requests library to grab recent messages. just be careful not to spam requests or discord might get mad lol

While it’s possible to fetch Discord messages without a bot, it’s not recommended due to potential Terms of Service violations. However, if you’re set on this approach, you could use Discord’s REST API with user authentication. You’d need to obtain your user token (keep it secret!) and make GET requests to the messages endpoint.

Here’s a basic idea:

import requests

headers = {'Authorization': 'YOUR_USER_TOKEN'}
channel_id = 'CHANNEL_ID'
url = f'https://discord.com/api/v9/channels/{channel_id}/messages'

response = requests.get(url, headers=headers)
messages = response.json()

for message in messages:
    print(f"{message['author']['username']}: {message['content']}")

Remember, this method isn’t officially supported and could lead to account termination if misused. For a safer, supported method, I’d recommend reconsidering using Discord.py or another official Discord API wrapper.