This is what i have so far:
from discord import Embed
import os
import discord
bot=discord.Client()
nichDat=["|","~",".",",","!","pls"]
@bot.event
async def on_message(message):
if message.content != "NothingButABot":
return
for guild in bot.guilds:
print(guild.name)
for channel in guild.text_channels:
if "bot" not in channel.name:
async for message in channel.history(limit=200):
if not message.author.bot:
for dings in nichDat:
if dings not in message.content:
print(message.content)
What it should do: Print every message once that the bot can see if it isnt connected to a bot (That means none of the strings from nichDat is in it or it is not written by a bot. What it is doing: Printing every message, that was not written by a bot 5 times. What can i do that it is doing the right stuff?
CodePudding user response:
try replacing
for dings in nichDat:
if dings not in message.content:
print(message.content)
with
if any(dings not in message.content for dings in nichDat):
print(message.content)
Your code is setup as a loop in a way that it checks each of the strings on your nichtDat list individually and if that single string is not in the message it gets printed, so your filter should not be working correctly either.
CodePudding user response:
I just fixed it by making a search function and completely changing how it works. This is how:
from discord import Embed
import os
import discord
bot=discord.Client()
nichDat=["|","~",".",",","!","pls"]
def searchfor(dings1):
for dings in nichDat:
if dings1.startswith(dings) == False:
break
print(dings1)
@bot.event
async def on_message(message):
if message.content != "NothingButABot":
return
print(message)
await bot.change_presence(activity=discord.Streaming(name='24/7 chatting', url='https://www.youtube.com/watch?v=dQw4w9WgXcQ'))
print("2")
for guild in bot.guilds:
print(guild.name)
for channel in guild.text_channels:
print(channel.name)
if "bot" not in channel.name:
print("Oke")
async for message in channel.history(limit=200):
if not message.author.bot:
searchfor(message.content)