#Getting message content in a cmd
1 messages · Page 1 of 1 (latest)
This is the issue, lemme send my code here
@commands.command()
@commands.has_guild_permissions(ban_members=True)
async def count(self, ctx, start_number: int):
await ctx.message.delete()
def check(m):
return ctx.channel == m.channel
counter = start_number + 1
URL = "MY WBBHOOK"
while not counting_state.STOPPED:
try:
msg = await self.bot.wait_for('message', check=check)
# print(msg.content)
if not msg.author.id == 943171320542269470:
if str(counter) in str(msg.content):
counter += 1
await msg.delete()
urls = re.findall(
'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', msg.content.lower())
if not urls:
async with aiohttp.ClientSession() as session:
webhook = Webhook.from_url(URL, session=session)
await webhook.send(content=msg.content,avatar_url=msg.author.avatar,username=msg.author.name,allowed_mentions=discord.AllowedMentions(everyone=False, users=False, roles=False, replied_user=False))
else:
async with aiohttp.ClientSession() as session:
webhook = Webhook.from_url(URL, session=session)
await webhook.send(content=int(counter)-1,avatar_url=msg.author.avatar, username=msg.author.name,allowed_mentions=discord.AllowedMentions(everyone=False, users=False, roles=False, replied_user=False))
else:
await msg.delete()
except Exception as e:
print(e)
pass
else:
counting_state.STOPPED = False
return```
msg = await self.bot.wait_for('message', check=check)
For some reasons i do not get every message with this method
be more precise please
The bot should get the messages from a Channel, and deletes it. But when there are spaming then not every message is getting sent to the bot
basically a counting bot?
but with a command
If I had to guess it would be because the previous message had not finished processing. By the time the next message is sent.
you could either use on_message or try to make the message listening async
you can't put a async on_message event inside a command?
No, Its a hard problem to solve. It just like you said, you are not catching all of the messages because they are coming in to fast for the wait_for to catch than finish the while loop again than wait_for again
@shut canyon I fixed thanks to a on_message function. Thanks for the idea :D
np
How do i close this chat? @shut canyon