how to get my chat bot to remember custom responses in discord then put it in intents.json python

hello am trying to get my discord bot to remeber what its learned after i shut it down but each time i boot it up again to test it forget everything its learned
heres the code

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>import discord
from discord.ext import commands
import json
import asyncio
import random
# Load intents from intents.json
with open('intents.json', 'r') as intents_file:
intents_data = json.load(intents_file)
intents = intents_data.get('intents', [])
# Load custom responses from custom_responses.json
try:
with open('custom_responses.json', 'r') as custom_responses_file:
custom_responses = json.load(custom_responses_file)
except FileNotFoundError:
custom_responses = {} # Initialize an empty dictionary if the file doesn't exist
# Initialize the bot
bot = commands.Bot(command_prefix='!', intents=discord.Intents.all())
@bot.event
async def on_ready():
print(f'Logged in as {bot.user.name} ({bot.user.id})')
@bot.event
async def on_message(message):
if message.author.bot:
return # Ignore messages from other bots
# Check for custom responses first
if message.content.lower() in custom_responses:
await message.channel.send(custom_responses[message.content.lower()])
else:
# If no custom response, check predefined intents
for intent in intents:
if any(pattern.lower() in message.content.lower() for pattern in intent['patterns']):
response = random.choice(intent['responses'])
`your text` await message.channel.send(response)
break
else:
await message.channel.send("I'm not sure how to respond. Could you provide a custom response?")
await bot.process_commands(message)
@bot.command()
async def learn(ctx, *, response: str):
"""
Command to add a custom response.
Usage: !learn <user_input> <custom_response>
Example: !learn favorite_color Blue
"""
user_input, custom_response = response.split(maxsplit=1)
custom_responses[user_input.lower()] = custom_response
await ctx.send(f"Learned: '{user_input}' -> '{custom_response}'")
@bot.event
async def on_disconnect():
# Save custom responses to custom_responses.json when the bot disconnects
with open('custom_responses.json', 'w') as custom_responses_file:
json.dump(custom_responses, custom_responses_file, indent=4)
print("Bot is starting...")
loop = asyncio.get_event_loop()
loop.run_until_complete(bot.start('TOKEN'))
</code>
<code>import discord from discord.ext import commands import json import asyncio import random # Load intents from intents.json with open('intents.json', 'r') as intents_file: intents_data = json.load(intents_file) intents = intents_data.get('intents', []) # Load custom responses from custom_responses.json try: with open('custom_responses.json', 'r') as custom_responses_file: custom_responses = json.load(custom_responses_file) except FileNotFoundError: custom_responses = {} # Initialize an empty dictionary if the file doesn't exist # Initialize the bot bot = commands.Bot(command_prefix='!', intents=discord.Intents.all()) @bot.event async def on_ready(): print(f'Logged in as {bot.user.name} ({bot.user.id})') @bot.event async def on_message(message): if message.author.bot: return # Ignore messages from other bots # Check for custom responses first if message.content.lower() in custom_responses: await message.channel.send(custom_responses[message.content.lower()]) else: # If no custom response, check predefined intents for intent in intents: if any(pattern.lower() in message.content.lower() for pattern in intent['patterns']): response = random.choice(intent['responses']) `your text` await message.channel.send(response) break else: await message.channel.send("I'm not sure how to respond. Could you provide a custom response?") await bot.process_commands(message) @bot.command() async def learn(ctx, *, response: str): """ Command to add a custom response. Usage: !learn <user_input> <custom_response> Example: !learn favorite_color Blue """ user_input, custom_response = response.split(maxsplit=1) custom_responses[user_input.lower()] = custom_response await ctx.send(f"Learned: '{user_input}' -> '{custom_response}'") @bot.event async def on_disconnect(): # Save custom responses to custom_responses.json when the bot disconnects with open('custom_responses.json', 'w') as custom_responses_file: json.dump(custom_responses, custom_responses_file, indent=4) print("Bot is starting...") loop = asyncio.get_event_loop() loop.run_until_complete(bot.start('TOKEN')) </code>
import discord
from discord.ext import commands
import json
import asyncio
import random

# Load intents from intents.json
with open('intents.json', 'r') as intents_file:
    intents_data = json.load(intents_file)
    intents = intents_data.get('intents', [])

# Load custom responses from custom_responses.json
try:
    with open('custom_responses.json', 'r') as custom_responses_file:
        custom_responses = json.load(custom_responses_file)
except FileNotFoundError:
    custom_responses = {}  # Initialize an empty dictionary if the file doesn't exist

# Initialize the bot
bot = commands.Bot(command_prefix='!', intents=discord.Intents.all())


@bot.event
async def on_ready():
    print(f'Logged in as {bot.user.name} ({bot.user.id})')


@bot.event
async def on_message(message):
    if message.author.bot:
        return  # Ignore messages from other bots

    # Check for custom responses first
    if message.content.lower() in custom_responses:
        await message.channel.send(custom_responses[message.content.lower()])
    else:
        # If no custom response, check predefined intents
        for intent in intents:
            if any(pattern.lower() in message.content.lower() for pattern in intent['patterns']):
                response = random.choice(intent['responses'])
            `your text`    await message.channel.send(response)
                break
        else:
            await message.channel.send("I'm not sure how to respond. Could you provide a custom response?")

    await bot.process_commands(message)


@bot.command()
async def learn(ctx, *, response: str):
    """
    Command to add a custom response.
    Usage: !learn <user_input> <custom_response>
    Example: !learn favorite_color Blue
    """
    user_input, custom_response = response.split(maxsplit=1)
    custom_responses[user_input.lower()] = custom_response
    await ctx.send(f"Learned: '{user_input}' -> '{custom_response}'")


@bot.event
async def on_disconnect():
    # Save custom responses to custom_responses.json when the bot disconnects
    with open('custom_responses.json', 'w') as custom_responses_file:
        json.dump(custom_responses, custom_responses_file, indent=4)


print("Bot is starting...")
loop = asyncio.get_event_loop()
loop.run_until_complete(bot.start('TOKEN'))

then you got the custom_responses.json

{
“user_input_1”: “custom_response_1”,
“user_input_2”: “custom_response_2”
}

then the intents.json

{
“intents”: [

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> {
"tag": "google",
"patterns": [
"google",
"search",
"internet"
],
"responses": [
"https://www.youtube.com/watch?v=dQw4w9WgXcQ&pp=ygUXbmV2ZXIgZ29ubmEgZ2l2ZSB5b3UgdXA%3D"
]
},
{
"tag": "greeting",
"patterns": [
"Hi there",
"How are you",
"Is anyone there?",
"Hey",
"Hola",
"Hello",
"Good day",
"Namaste",
"yo"
],
"responses": [
"Hello",
"Good to see you again",
"Hi there, how can I help?"
],
"context": [
""
]
}
</code>
<code> { "tag": "google", "patterns": [ "google", "search", "internet" ], "responses": [ "https://www.youtube.com/watch?v=dQw4w9WgXcQ&pp=ygUXbmV2ZXIgZ29ubmEgZ2l2ZSB5b3UgdXA%3D" ] }, { "tag": "greeting", "patterns": [ "Hi there", "How are you", "Is anyone there?", "Hey", "Hola", "Hello", "Good day", "Namaste", "yo" ], "responses": [ "Hello", "Good to see you again", "Hi there, how can I help?" ], "context": [ "" ] } </code>
    {
        "tag": "google",
        "patterns": [
            "google",
            "search",
            "internet"
        ],
        "responses": [
            "https://www.youtube.com/watch?v=dQw4w9WgXcQ&pp=ygUXbmV2ZXIgZ29ubmEgZ2l2ZSB5b3UgdXA%3D"
        ]
    },
    {
        "tag": "greeting",
        "patterns": [
            "Hi there",
            "How are you",
            "Is anyone there?",
            "Hey",
            "Hola",
            "Hello",
            "Good day",
            "Namaste",
            "yo"
        ],
        "responses": [
            "Hello",
            "Good to see you again",
            "Hi there, how can I help?"
        ],
        "context": [
            ""
        ]
    }

etc

any help would be helpful to me thanks you for you time as well

i want it to remember what you tell it like if you say !learn cat cat is good next time you boot it you say cat i want it to say cat is good

New contributor

hutcch is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật