On my discord bot (python) I am trying to detect or rather to check a sent message within a command: if someone types the command $start the command should check in a while loop which messages are being sent after the $start command. If the sent message is "join", the user who sent the message should be added to a list. I was trying to detect and save messages in a variable via the on_message() function but it doesnt seem to work and I dont think that my code makes that much sense, but I dont know how to properly implement it.
import discord
from discord.ext import commands
client = commands.Bot(command_prefix = "$")
@client.event
async def on_ready():
print("started")
sentMsg = ""
users = []
@client.event
async def on_message(msg):
if msg.author == client.user:
return
else:
sentMsg = msg.content
print(sentMsg)
@client.command()
async def start(ctx):
print(sentMsg)
await ctx.send("starting ...")
users.append(ctx.author)
while True:
if sentMsg == "join":
ctx.send("Joined!")
sentMsg = ""
client.run(*token*)
I put the sentMsg varibale to the Watch-section in VS-Code and it always says "not available" although it prints the right values. Also when hovering over it in on_message() it says: "sentMsg" is not accessed Pylance. Can anyone improve my code or does anyone have a better idea to implement this?
I'd appreciate anyone's help