FIXED
(see below)
I am making a discord AI chatbot trained off messages sent in the server. I need to take all messages that have been sent in the general channel, put them in a list, and get their ‘content’ value. Here is what I have been trying:
@bot.event
async def on_message(message):
channel = discord.utils.get(message.guild.text_channels, name="general")
#print(channel.history())
messages = [message async for message in channel.history()]
print(messages)
when I run this code, It gives me a list with data from each message sent in the general channel. This data looks something like this when printed in the terminal:
<Message id=1254275339253846027 channel=<TextChannel id=1254271988826898462 name='general' position=0 nsfw=False news=False category_id=1254245331667783744> type=<MessageType.default: 0> author=<Member id=775486294435954689 name='nosics' global_name='Nosics' bot=False nick=None guild=<Guild id=1254245331667783743 name="Nosics's server" shard_id=0 chunked=True member_count=2>> flags=<MessageFlags value=0>>
There should be a ‘content’ variable listed in that data, but for some reason there is not. I can do things like
print(message.id)
and it works just fine. But for whatever reason, message.content doesnt exist, or is at least not given to me. Any ideas?
EDIT:
I fixed my problem! Not sure what the original issue was, but I found a way that works:
@bot.event
async def on_message(message):
channel = discord.utils.get(message.guild.text_channels, name="general")
counter = 0
async for message in channel.history(limit=999999):
counter += 1
print(counter)
print(message.content)
hope this helps anyone who has a simmilar problem!