I’m trying to make a discord bot respond when someone makes laughing remarks but it infinitely sends gifs whenever someone types anything code is as follows
JavaScript
x
30
30
1
import os
2
import discord
3
import random
4
from discord.ext import commands
5
import keep_alive
6
Bot_Token = os.environ['Bot_Token']
7
bot = discord.Client()
8
9
@bot.event
10
async def on_ready():
11
guild_count = 0
12
13
for guild in bot.guilds:
14
print(f"- {guild.id} (name: {guild.name})")
15
guild_count = guild_count + 1
16
17
print("AGOP_Bot is in " + str(guild_count) + " guilds.")
18
19
@bot.event
20
async def on_message(message):
21
if message.content == "AGOP~hello":
22
await message.channel.send("https://c.tenor.com/tTXwGpHrqUcAAAAC/summoned.gif")
23
24
if message.content == "Lmao" or "Lol" or "lmao" or "lol" and message.author.id != bot_id:
25
response_funny = ["https://c.tenor.com/mUAgLfICUC0AAAAC/i-didnt-get-the-joke-abish-mathew.gif","https://c.tenor.com/zdoxFdx2wZQAAAAd/not-funny-joke.gif","https://i.pinimg.com/originals/f5/53/97/f55397a7de1c82b37d6d62e655a0e915.gif","https://jutsume.com/images2/2022/04/16/is-this-some-peasant-joke-meme.png","https://c.tenor.com/FnASqUdvJH4AAAAC/whats-so-funny-john.gif"]
26
await message.channel.send(random.choice(response_funny))
27
28
bot.run(Bot_Token)
29
keep_alive.py
30
Advertisement
Answer
JavaScript
1
20
20
1
import os
2
import discord
3
import random
4
from discord.ext import commands
5
# import keep_alive
6
Bot_Token = os.environ['Bot_Token']
7
bot = discord.Client()
8
9
@bot.event
10
async def on_message(message):
11
if message.content == "AGOP~hello":
12
await message.channel.send("https://c.tenor.com/tTXwGpHrqUcAAAAC/summoned.gif")
13
14
if message.content in ("Lmao" or "Lol" or "lmao" or "lol") and message.author.id != bot.user:
15
response_funny = ["https://c.tenor.com/mUAgLfICUC0AAAAC/i-didnt-get-the-joke-abish-mathew.gif","https://c.tenor.com/zdoxFdx2wZQAAAAd/not-funny-joke.gif","https://i.pinimg.com/originals/f5/53/97/f55397a7de1c82b37d6d62e655a0e915.gif","https://jutsume.com/images2/2022/04/16/is-this-some-peasant-joke-meme.png","https://c.tenor.com/FnASqUdvJH4AAAAC/whats-so-funny-john.gif"]
16
await message.channel.send(random.choice(response_funny))
17
18
bot.run(Bot_Token)
19
# keep_alive.py
20
In addition to some formatting, I changed some of the variables for the API calls. I commented out the keep_alive.py as I assume you are using that to keep your code hosted on Repl.it or something, and you can just comment it back in. I was also able to get this code to work with my bot and execute as you want.