I want to develop my own custom chatbot but I get some issue during the development, I want to use Specific Response Adapter in chatterbot. There is a sample of code.
from chatterbot.trainers import ListTrainer
from chatterbot import ChatBot
from chatterbot.trainers import ChatterBotCorpusTrainer
bot = ChatBot('Mybot',
storage_adapter='chatterbot.storage.SQLStorageAdapter',
logic_adapters=[{'import_path': 'chatterbot.logic.SpecificResponseAdapter',
'input_text': 'Help me!',
'output_text': 'Ok'
}]) # Crate Chatbot
trainer = ListTrainer(bot)
text = open('/content/drive/My Drive/Chatbot/Data/data.txt').readlines()
trainer.train(text)
while True:
request = input("Your: ")
response = bot.get_response(request)
print("bot:",response)
This is the output:
Your: Help me!
bot: I am sorry, but I do not understand.
Your: 'Help me!'
bot: I am sorry, but I do not understand.
please help me to solve this problem
Related
I am writing a program that screenshots my computer screen and send it to my discord channel. This is done by a discord bot made by me. Below shows what I did:
First, define a function that does a screenshot:
import keyboard
import mouse
import os
def screenshot():
keyboard.press('win + shift + s')
time.sleep(1.5)
mouse.press('left')
mouse.drag(0, 0, 1600, 850, duration=0.2)
mouse.release('left')
filename = f"Screenshot_{time.strftime('%Y%m%d')}_{time.strftime('%I%M%S')}.png"
os.chdir('Path_of_screenshot_saves_here') # I have tested it, the path is correct
time.sleep(1)
with open(filename, 'r') as f:
return f
Then, the code of the discord bot:
import discord
import keyboard
import time
import os
import mouse
intents = discord.Intents.default()
intents.message_content = True
client = discord.Client(intents=intents)
#client.event
async def on_ready():
print(f'Logged in as {client.user}')
#client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('$ss'): # sends a screenshot when it receives a message starts with '$ss'
await message.channel.send(screenshot())
client.run('my_bot_token_here')
The bot does send something to the channel. However, instead of sending out a png file, it sends something like this:
<io.TextIOWrapper name='Screenshot_20230219_030537.png' mode='r' encoding='cp1252'>
What have I done wrong? Are there any ways to solve this? Thanks for any help in advance.
I want to become a fake discord bot, so i can use: !!send or something like that.
I have the token ready and i tried some repl.it templates but i have no idea of what to do.
here is the code i tried:
import discord
import os
import time
import discord.ext
from discord.utils import get
from discord.ext import commands, tasks
from discord.ext.commands import has_permissions, CheckFailure, check
os.environ["TOKEN"] = "no-token-for-you-to-see-here"
#^ basic imports for other features of discord.py and python ^
client = discord.Client()
client = commands.Bot(command_prefix = '!!') #put your own prefix here
#client.event
async def on_ready():
print("bot online") #will print "bot online" in the console when the bot is online
#client.command(pass_context=True)
async def send(ctx,*,message):
await client.say(message)
client.run(os.getenv("TOKEN")) #get your bot token and create a key named `TOKEN` to the secrets panel then paste your bot token as the value.
#to keep your bot from shutting down use https://uptimerobot.com then create a https:// monitor and put the link to the website that appewars when you run this repl in the monitor and it will keep your bot alive by pinging the flask server
#enjoy!
It was online, but the command didn't work.
The command send should be
#client.command()
async def send(ctx, *, message: str):
await ctx.send(message)
Also, you're defining two client(s). You need only one.
client = commands.Bot(command_prefix = '!!')
You're also importing some useless modules that you don't need right now.
Your final code should look like this:
import discord
from discord.ext import commands
client = commands.Bot(command_prefix="!!")
#client.event
async def on_ready():
print("The bot is online")
#client.command()
async def send(ctx, *, message: str):
await ctx.send(message)
client.run("token-of-the-bot")
Please tell me if it works or not. Have a great day :)
import discord
import random
from discord.ext import commands, tasks
from itertools import cycle
from random import choice
client = commands.Bot(command_prefix = '.')
intents = discord.Intents.all()
#client.command()
#commands.guild_only()
async def ruser(ctx):
await ctx.send(choice(ctx.guild.members))
This is some code for a discord bot I'm working on. If you type ".ruser", it's supposed to send a message saying the user. The problem is that it is only returning the bots name, and not any of the users.
You didn't actually pass in the intents, you only declared the variable. You're supposed to add them to your bot as well.
intents = discord.Intents.all()
client = commands.Bot(command_prefix='.', intents=intents)
I'm attempting to make a Custom Search command using the Custom Search API.
Naturally I have no idea how to implement it. I'm hoping someone can take a look at what I have and help me figure out how to make it work in this style?
import discord
from discord.ext import commands
import discord.utils
import time
import os
import dotenv
from dotenv import load_dotenv
load_dotenv()
SEARCH = os.getenv("CUSTOM_SEARCH_API_KEY")
class Util(commands.Cog):
def __init__(self, client):
self.client = client
#commands.command(name="Search", aliases=["search"])
#commands.has_permissions(embed_links=True, add_reactions=True)
async def _search(self, ctx, *, message):
if not ctx.author.Bot:
guild = ctx.guild
msg = ctx.message
cli = self.client.user
gold = discord.Color.dark_gold()
embed = discord.Embed(color=gold, name=f"{image.name}", description=f"{image.desc}", timestamp=msg.created_at)
embed.set_image(url=f"{image.url}")
embed.set_thumbnail(url=cli.avatar_url)
embed.set_footer(text=guild.name, icon_url=guild.icon_url)
await ctx.send(embed=embed)
return
def setup(client):
client.add_cog(Util(client))
I'm using dotenv to store my API key
Basically, I'm wanting it to be a somewhat detailed command.
If searching for posts it will find the exact post. and if searching for images it will go by tag and find a random image matching the selected tag(s).
I would like for it to respond via rich embed if possible.
I'm fully aware my above code won't work at all. I simply put it there as a base for part of the embed that I want to try to implement.
Some help would be much appreciated.
I'm using discord.py rewrite and I have my commands set up through cogs.
This is my bot.py file that contains the handler for my cogs.
import discord
from discord.ext import commands
import os
import json
import dotenv
from dotenv import load_dotenv
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
PREFIX = os.getenv("COMMAND_PREFIX")
client = commands.Bot(command_prefix=PREFIX)
client.remove_command('help')
for filename in os.listdir("./cogs"):
if filename.endswith(".py"):
client.load_extension(f"cogs.{filename[:-3]}")
client.run(TOKEN)
I have the following python script that is connecting to Google Dialogflow using Flask and is using a webhook to retrieve the response from Google Dialogflow.
The limitation is that I currently only enter the query in to the Google Dialogflow frontend, with the result returned here in variable result
However how can I use this same script to submit the query to Google Dialogflow, instead of entering in the front end?
Any help appreciated, thanks!
import json
import os
from flask import Flask
from flask import request
from flask import make_response`
`enter code here # Flask app should start in global layout
app = Flask(__name__)
#app.route('/webhook', methods=['POST'])
def webhook():
req = request.get_json(silent=True, force=True)
res = processRequest(req)
res = json.dumps(res, indent=4)
r = make_response(res)
r.headers['Content-Type'] = 'application/json'
return r
def processRequest(req):
result = req.get("queryResult")
result_message = result['fulfillmentText']
print(result_message)
#app.route('/test', methods=['GET'])
def test():
return "Hello there my friend !!"
if __name__ == '__main__':
port = int(os.getenv('PORT', 5000))
app.run(debug=True, port=port, host='0.0.0.0')`
I discovered shortly after posting this that a webhook is whats known as a reverse API, and only shows results as opposed to two way interactions.