0
votes

I'm making a bot for a Minecraft server's discord. I have an on_member_join event and an on_message event below it. The on_member_join works perfectly, but when I send a message in the discord server, nothing inside the on_message event happens. Here is my code, if someone has a possible solution I would really appreciate it.

import discord
import os
import datetime

intents = discord.Intents(members = True, guilds = True)
client = discord.Client(intents = intents)
yesterday = datetime.datetime.now() - datetime.timedelta(days=1)
joinList = []

@client.event
async def on_ready():
  global verify
  print('We have logged in as {0.user}'.format(client))

@client.event
async def on_member_join(member):
  await client.get_channel(809271484475506698).send('Welcome, <@' + str(member.id) + '>! Please enter your main Minecraft username into this channel.')
  joinList.append(str(member.name))
  print(joinList)

@client.event
async def on_message(message):
  print('test')

  print(joinList)
  messages = await client.get_channel(809256065387462696).history(after = yesterday).flatten()

  if str(message.author.name) in joinList:
    for i in range(len(messages)):
      if message.content in str(messages[i]):
        print('success!')
        return

client.run(os.getenv('TOKEN'))
1
Does the print('test') also not work? - Aditya Tomar
No, I don't get anything in the console after sending messages - Gabe Palmer
Does the bot have full access to that channel? - FlexGames

1 Answers

0
votes

Add this to the beginning of your program, with the rest of your imports: from discord.utils import get. You need to include this, because you're using client.get_channel, which requires you to import get first.