Okay so I have a music bot code that was working before I switched to another virtual machine provider. All the requirements are exactly the same as in my previous virtual machine because I copy and pasted everything including the requirements.txt. The bot runs normally with 0 errors until I try to run any of the commands. It gave me this error:
discord.ext.commands.errors.CommandNotFound: Command "play" is not found
I've tried rolling back to the rewrite version I started the project on,
changed #client.command to #bot.command after assigning bot = commands.Bot(command_prefix='prefix')
#I've assigned client = discord.ext.commands
#client.command(name='play', aliases=['sing'])
async def play(self, ctx, *, search: str):
#then some code
update 1: Ran it as a cog and raised:
discord.ext.commands.errors.ExtensionFailed: Extension 'music' raised an error: TypeError: cogs must derive from Cog
update 2: No idea why rolling back the rewrite version didn't work though. Perhaps I didn't do it correctly.
Just simply run it as a cog.
Note that the way cogs work has been updated recently:
https://discordpy.readthedocs.io/en/latest/ext/commands/cogs.html
If you still want to run it as a standalone bot,
your bot should looks like something along the lines of:
from discord.ext.commands import Bot
bot = Bot("!")
#bot.command(name='play', aliases=['sing'])
async def play(ctx, *, search: str): # Note no self
#then some code
bot.run("token")
It's important that the bot that you run is the same bot that you register the commands with. You're also passing self to your bot even though it's not in a cog, which doesn't make sense.
Okay so I found the problem.
The bot doesnt work when I try to run it as a standalone bot.
The reason using it as a cog don't work the first time was because.
the way cogs work has been changed in discord.py rewrite.
These are the changes I made:
#in cogs/music.py
class Music:
#Code
#bot.event
async def on_ready():
print('Music bot online')
to
#in cogs/music.py
class Music(commands.Cog):
#Code
#commands.Cog.listener()
async def on_ready():
print('Music bot online')
Thank you to the legendary #PatrickHaugh for helping me figure this out.
Related
I am currently trying to program my own Discord Bot with Python. I have now made an "on_message" event, but "message.content" is not returning anything. No message, nothing! Can you help me?
#client.event
async def on_message(message):
if message.content.startswith("$test"):
await message.channel.send("test")
You don't have the message_content intent, so you can't read messages.
Docs: https://discordpy.readthedocs.io/en/latest/intents.html
Don't forget to enable them on your dev portal as well.
Also, instead of manually parsing messages with prefixes, consider using the built-in Commands framework that does all this for you. Docs: https://discordpy.readthedocs.io/en/latest/ext/commands/commands.html
PS "null" is not a thing in Python, it's None. And the message content isn't None/"null", it's an empty string ("").
I saw a question for a discord bot and it was using a library called "keep_alive". How can I import it to my bot if it does keep the bot online?
The below code is the keep_alive code which prevents your repl from dying by creating a flask server. You should use uptime-robot to make the server gets pinged in a certain amount of time to make it work for long time without stopping.
from flask import Flask
from threading import Thread
app = Flask('')
#app.route('/')
def main():
return "Your bot is alive!"
def run():
app.run(host="0.0.0.0", port=8080)
def keep_alive():
server = Thread(target=run)
server.start()
You should create a keep_alive and paste the above code there and then add keep_alive.keep_alive() in your main file to make it work.
You can refer this youtube-video to understand how to use that
I am trying to make a command that has an interaction like this:
User: p.poesia (text) #user
Bot: (text copied)
#user, 2021
Please consider reading the discord.py documentation.
This is the basic code I made for you to run it.
#client.command()
async def poesia(ctx, text):
await ctx.send(text + str(ctx.author))
Need help please.
My bot respond with correct answer during the online training, and when I confirm the answer he want to give, it works (use a custom action to asnwer). How ever when I try my bot with actual dialogue It don’t work.
the sénarion will be like:
User: Bonjour
Bot: Bonjour écrivez votre problème
User: mon probleme est: bla bla
Nothing from bot
This sénario is when trying to run the bot.
But before that when using online training the bot respond correctly with the custom action.
In my stories file I have something like:
## Generated Story -960033508281559891
bonjour
- utter_bonjour
confirmer
- utter_etape1
problème_site
- SendIntent_probleme_site
- utter_problème_site
So according to my story file the bot should do the action SendIntent_probleme_site. The class for this action is:
class SendIntent_probleme_site(Action):
def name(self):
return ‘SendIntent_probleme_site’
def run(self, dispatcher, tracker, domain):
message = tracker.latest_message.text
return [SlotSet(‘intent_probleme_site’, message)]
I do this to store the intent_probleme as a slot to use it later
Any help please? I also don’t know how to do something that tell me were is the problem like a log or exception, etc.
Thank you
I need the bot to delete the message from the command author, and leave the bot message. Any help will be appreciated! thank you.
I have already tried looking for a answer on google but nothing has worked
I'm kinda late here. I tried implementing this with the new 1.0 terms but couldn't make it work. If anyone has an updated version, please do tell
Edit: I found that the new best way of doing it is to just add this at the end of the function:
await ctx.message.delete()
No need for a separate delete function anymore.
You can obtain the message that called the command by passing the context with the command using the pass_context option. You can use the Client.delete_message coroutine to delete messages.
from discord.ext import commands
bot = commands.Bot(command_prefix='!')
#bot.command(pass_context=True)
async def deletethis(ctx):
await bot.say('Command received')
await bot.delete_message(ctx.message)
await bot.say('Message deleted')
bot.run('token')