I have a discord bot with admin permissions in my server, which is responsible for gathering all messages from a particular channel, and then storing them in my database. However the code I have written does not work.
import discord
application_id = "--hidden--"
public_key = "--hidden--"
bot_token = "--hidden--"
channel_id = 1016551171495829605
intents = discord.Intents.default()
intents.message_content = True
client = discord.Client(intents=intents)
@client.event
async def get_mes():
for i in client.guilds:
for j in i.text_channels:
if j.id == 1016551171495829605:
return await (j.history())
client.run(bot_token)
print("getting messages")
x = get_mes()
print("got messages")
However, I dont understand how the discord.py library handles events, and how I can run scripts that can make calls to the API, only for information, rather than for events. I'd like to be able to get the entire discord channel history of messages using the discord.py library. How would I do this?