I want to implement a command in my bot, to allow fetching messages from a channel and process them further.
I tried to look for how to fetch messages from a specific channel, but could not find an explicit answer to it, except most of the forum pages simply refer to the API page, with some saying trying the discord.utils.get
method.
I am wondering if it would be something like this, but I could not find the matching methods/attributes that I can use to do this:
@bot.command(name='fetchmessages', help='....')
async def fetchmessages(ctx, from_channel_id:str, from_date:str):
#check if the channels already exist
channel = discord.utils.get(ctx.guild.channels, id=from_channel_id)
from_date = .... #code to parse the string to a date object
discord.utils.get(channel.messages, # Q1
from=from_date) # Q2
####
However, I cannot really do this because
- Q1: assuming the channel is a
TextChannel
link, the class does not have an attribute that gives me all the messages from that channel, but onlylast_message
. WhileTextChannel
has a methodfetch_message
but that only gets a single message with an ID parameter - Q2: I am not sure if I can pass a date object like this, because the API for
discord.utils.get
does not explicitly say what attributes (**attrs
) can be specified.
Any hints much appreciated.
Thanks