mirror of https://github.com/sgoudham/Enso-Bot.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.8 KiB
Python
53 lines
1.8 KiB
Python
5 years ago
|
import asyncio
|
||
|
import random
|
||
|
|
||
|
from discord.ext import commands
|
||
|
from discord.ext.commands import BucketType, cooldown, command
|
||
|
|
||
|
from cogs.anime.interactive import error_function
|
||
|
|
||
|
|
||
|
# Set up the cog
|
||
5 years ago
|
class eightball(commands.Cog):
|
||
5 years ago
|
def __init__(self, bot):
|
||
|
self.bot = bot
|
||
|
|
||
|
# ~8Ball command
|
||
|
@command(name="8ball", aliases=['8Ball'])
|
||
|
# Added a cooldown, only 1 instance of the command can be sent every second per user
|
||
|
@cooldown(1, 1, BucketType.user)
|
||
|
async def _8ball(self, ctx, *, question):
|
||
|
# Setting up the channels that the commands can be sent in enso-chan-commands and general
|
||
|
channels = ["enso-chan-commands", "general", "picto-chat"]
|
||
|
|
||
|
# Surround with try/except to catch any exceptions that may occur
|
||
|
try:
|
||
|
|
||
|
# If the channel that the command has been sent is in the list of accepted channels
|
||
|
if str(ctx.channel) in channels:
|
||
|
|
||
|
# Open the file containing all the custom eightball responses
|
||
5 years ago
|
with open('images/FunCommands/eightball.txt', encoding="utf8") as file:
|
||
5 years ago
|
# Store the eightball responses in an array
|
||
5 years ago
|
eightball_array = file.readlines()
|
||
5 years ago
|
# Repeat the user question and send out a random response from _8ball_array
|
||
5 years ago
|
await ctx.send(f'Question: {question}\nAnswer: {random.choice(eightball_array)}')
|
||
5 years ago
|
|
||
|
# else the command is sent in an invalid channel
|
||
|
else:
|
||
|
|
||
|
# Call error_function() and display it to the user
|
||
|
message = await ctx.send(error_function())
|
||
|
|
||
|
# Let the user read the message for 2.5 seconds
|
||
|
await asyncio.sleep(2.5)
|
||
|
# Delete the message
|
||
|
await message.delete()
|
||
|
|
||
5 years ago
|
except Exception as e:
|
||
5 years ago
|
print(e)
|
||
|
|
||
|
|
||
|
def setup(bot):
|
||
5 years ago
|
bot.add_cog(eightball(bot))
|