I'm coding a bot for a friend and they have asked me to make an 8ball command. You think it seems easy.. but they don't want the prefix included the command. So it would be like this:
BotName, do you think today will be a good day?
I've tried using @client.event but I don't know how to make it so that the user can say their own question, but have the bots name at the front of the question.
So like this:
BotName, do you think today will be a good day?
The BotName part will need to be included to trigger the event. Then they can say what they want. Like this (example was already given above):
BotName, do you think today will be a good day?
Here is some code I tried:
import discord
from discord.ext import commands
import random
class eightball(commands.Cog):
def __init__(self, client):
self.client = client
@commands.Cog.listener()
async def on_message(self,message):
#botname = [f"BotName, {message}?"] #tried this too
# if message.content in botname: #tried this too
if f'BotName, {message.author.content}?' in message.content:
responses = ['Responses here.']
await message.channel.send(f'{random.choice(responses)}')
await self.client.process_commands(message)
def setup(client):
client.add_cog(eightball(client))
If it's not possible then do not worry! (Sorry if I didn't explain as well as I could and if I sound dumb or something.)
1 Answer 1
I guess you can make it work with a bit more logic.
if message.content.startswith('BotName,'):
#rest of the code
Consider that if they @ your bot, the string would be <@1235574931>, do you think today will be a good day?
So, it'll only work if they add specifically whatever BotName would be.
Also, cog listeners doesn't need await self.client.process_commands(message)