0

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.)

asked Jul 8, 2021 at 18:00

1 Answer 1

0

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)

answered Jul 8, 2021 at 19:46
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.