The repl: https://replit.com/@Jojaypro1THE/3-Slash-Commands?v=1
When I send /balance, the bot is not responding
This is probably because discord thinks you are trying to run a slash command, Try changing the prefix from /
to something else.
I changed the prefix to !
It is still not working
Lol Oh Good I ain’t the only one who is having this problem lol
You’re using on_message
event and commands.Bot
at the same time. If you override the on_message
event, the bot commands won’t be processed.
You can fix this by adding await bot.process_commands(message)
at the end of your on_message
function.
@bot.event
async def on_message(message):
if message.author == bot.user:
return
knownUser = False
keys = db.keys()
if str(message.author.id) in keys:
knownUser = True
else:
db[str(message.author.id)] = None
if message.content.startswith("$hello"):
await message.channel.send("Hello!")
if "hello" in message.content.lower() and not knownUser:
await message.channel.send(f"Hello there <@{message.author.id}>! I'm a bot that lets you play the currency game, try /helpMeBot to find out more.")
# Add here
await bot.process_commands(message)
Same case as yours. As it is said here in the docs:
This function is a coroutine.
This function processes the commands that have been registered to the bot and other groups. Without this coroutine, none of the commands will be triggered.
By default, this coroutine is called inside the
on_message()
event. If you choose to override theon_message()
event, then you should invoke this coroutine as well.
I have no Idea what your talking about lol. This is my 6th day using python lol. I figured I try out a bot program while I am doing my 100 days of code in python challenge on here. Lol
Do you mean something like this?
@bot.event
async def on_ready():
print('We have logged in as {0.user}'.format(bot))
@bot.event
async def on_message(message):
if message.author == bot.user:
return
knownUser = False
keys = db.keys()
if str(message.author.id) in keys:
knownUser = True
else:
db[str(message.author.id)] = None
if message.content.startswith("$hello"):
await message.channel.send("Hello!")
if "hello" in message.content.lower() and not knownUser:
await message.channel.send(f"Hello there <@{message.author.id}>! I'm a bot that lets you play the currency game, try /helpMeBot to find out more.")
if message.content.startswith("balance")
await message.channel.send("Balance: 0")
try:
bot.run(my_secret)
except Exception as err:
raise err
Let’s get to the basics. This a part of your code:
@bot.event
async def on_message(message):
if message.author == bot.user:
return
@bot.event
: This is a decorator (which is used by the library discord.py) that registers an event. An event in discord.py is something that happens on Discord that you can use your bot to respond to, like sending a new message! Which is this case, you’re registering the on_message
event.
async def on_message(message)
: The on_message
event is triggered whenever a message is sent in the server your bot is in. The function is async
because it’s a coroutine, meaning it’s designed to be used with Python’s asyncio
library.
That being said you are also using in your code the function commands.Bot
which is a coroutine.
But, the discord.py documentation explictly said this about commands.Bot
:
Meaning that you have to invoke the commands.Bot
inside your on_message()
event!
So you will just add a line in your code, the coroutine that discord.py said, which is
await bot.process_commands(message)
So, your code from the event on_message()
will go from this:
@bot.event
async def on_message(message):
if message.author == bot.user:
return
knownUser = False
keys = db.keys()
if str(message.author.id) in keys:
knownUser = True
else:
db[str(message.author.id)] = None
if message.content.startswith("$hello"):
await message.channel.send("Hello!")
if "hello" in message.content.lower() and not knownUser:
await message.channel.send(f"Hello there <@{message.author.id}>! I'm a bot that lets you play the currency game, try /helpMeBot to find out more.")
To this:
@bot.event
async def on_message(message):
if message.author == bot.user:
return
knownUser = False
keys = db.keys()
if str(message.author.id) in keys:
knownUser = True
else:
db[str(message.author.id)] = None
if message.content.startswith("$hello"):
await message.channel.send("Hello!")
if "hello" in message.content.lower() and not knownUser:
await message.channel.send(
f"Hello there <@{message.author.id}>! I'm a bot that lets you play the currency"
" game, try /helpMeBot to find out more."
)
# You add this line right here!!!!
await bot.process_commands(message)
I have to give you props you are one heck of a guy! One day I hope to be on your level!
As soon as I figure out how too. lol
There is a checkbox below his post. Click that and it will be marked as a Solution.
Maybe because I ain’t original poster I can’t mark it. I don’t see any checkbox
I get it now. Its kind of like a javascript class. Where you have to call out the command in the class that is running.
I believe so he isn’t commenting back. But being able to supply so much information so quickly was very very helpful for me
It is now working, thx
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.