1
1
1 22021-07-21 11:48:44
Python
1 2, 2021-07-21 11:48:44

Discord.py how to get a message by its id?

There is a specific post id, I try to get its content like this:

await me.get_guild(guild.id).get_channel(channel.id).fetch_message(message.id)


but I'm having a problem:
discord.errors.Forbidden: 403 Forbidden (error code: 20002): Only bots can use this endpoint


Full code:
@me.event
async def on_ready():
  main_create_folder()

  checkComplited = 1

  for guild in me.guilds:
    for channel in me.get_guild(guild.id).channels:
      
      messages = ""

      if isinstance(channel, discord.channel.TextChannel):
        try:
          fileChannel = open(f"servers\{guild.id} ({guild.name})\{channel}.txt", 'w')

          for message in await channel.history(limit=500).flatten():
            messages += f"[{message.author.name}#{message.author.discriminator}]: {await me.get_guild(guild.id).get_channel(channel.id).fetch_message(message.id)}\n"

          fileChannel.write(f"{messages}")
          fileChannel.close()

          log(2, None, channel, checkComplited)
        except:
          log(3, None, channel, checkComplited)

        checkComplited += 1

    log(4, guild)

  log(5)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question