-1
import discord
import TOKEN_value
import memes
client = discord.Client()
TOKEN = TOKEN_value.token()
memes_ON = False
@client.event
async def on_ready():
print('BOT HAS BEEN CONNECTED.')
print(client.user.name)
print(client.user.id)
@client.event
async def on_message(message):
global memes_ON
if message.content.lower().startswith('!memes'):
memes_ON = True
await message.channel.send('Now I gonna send memes for you!')
if memes_ON:
meme = memes.memes_search()
if meme != 'no memes here':
await message.channel.send(meme)
client.run(TOKEN)
The function memes_search() returns me a link from some meme of Imgur, but it is never a repeated link, IE, not always have something new to send, and in this case it returns the string 'no memes here'.
The token() function just returns my token
What I would like to do is that every time I had a new link it was automatically sent to the chat in the place that was typed ! memes, but it stops running if there are no new links and only comes back if someone sends a message on the server. The only way it worked was to send messages endlessly even if they are not links, otherwise it stops running. I’ve tried a lot of things and none of them work. What I need is that the function does not stop running and continue doing the check "if memes_ON", I tried to print some values and saw that from the moment that a link is not returned it runs the function twice and until have new messages on the server.
await only runs if it is within an async function. I tried to write asyncio.Gather(client.run(TOKEN), meme_loop()) and it works the bot normal but the function of sending memes does not
– Obb
@Obb You could add
print
s within the functionmeme_loop
1) before the while, to see if the function is running; and 2) before the for, to see the result of the variablememe
in each iteration? Maybe no meme is being sent bymemes.memes_search()
.– enzo
Got it, buddy. Thanks a lot! I made a loop inside the main function and a few more changes.
– Obb