Как сделать, чтобы дискорд бот мог работать только в одном текстом канале, а не во всех?

У меня есть дискорд-бот, но он имеет доступ ко всем чатам на сервере ,как можно его ограничить, чтобы он имел доступ только одному чату?-

Вот код -

import discord
from discord.ext import commands
from discord import Client, Intents
from discord_slash import SlashCommand
import sqlite3
import os
from dotenv import load_dotenv
import datetime
import colorama
from colorama import Fore

load_dotenv()
TOKEN = os.getenv("TOKEN")


noter = Client(intents=Intents.default())
slash = SlashCommand(noter, sync_commands=True)
botver = 'v0.2.2'

guild_ids = [903941822617899008]

@noter.event
async def on_ready():
    print(Fore.WHITE + "[" + Fore.GREEN + '+' + Fore.WHITE + "]" + Fore.GREEN + f" connection established and logged in as: {noter.user.name} with ID: {noter.user.id}")

@slash.slash(name='suka_v_chem_delo', description='Shows you all of the bots commands.', guild_ids=guild_ids)
async def suka_v_chem_delo(ctx):
    
    helpembed = discord.Embed(title="Commands", description='A helpful menu for all the commands this bot can do! | Made by Sushka_#5709', colour=0x941db4, timestamp=datetime.datetime.utcnow())
    helpembed.set_thumbnail(url='https://cdn.discordapp.com/avatars/591665811484049429/9e3054188305485285ac092157ffe6a1.png?size=128')
    helpembed.add_field(name="▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬", value='\u200b', inline=False)
    helpembed.add_field(name="/ping", value = "Ping Pong. (Pings the bot)", inline=False)
    helpembed.add_field(name="/db make", value = "Makes the database for the notes and usernames and IDs.", inline=False)
    helpembed.add_field(name="/note add `userID` `username` `note` `friend_code` `sex`", value = "Adds a user, their ID and a note to the database.", inline=True)
    helpembed.add_field(name="/note rmv `userID`", value = "Remove users from database. Along with notes and data.", inline=True)
    helpembed.add_field(name="/note show `userID`", value = "Gets username, ID, note and other from database.", inline=True)
    helpembed.add_field(name="/suka_v_chem_delo", value = "Help with the bot", inline=False)
    helpembed.add_field(name="\u200b", value='▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬', inline=False)
    await ctx.send(embed=helpembed)


@slash.slash(name="Ping", description="Standard ping command to check latency.", guild_ids=guild_ids)
async def ping(ctx):
    pembed = discord.Embed(title="Pong!", description=f"My connection speed is {round(noter.latency * 1000)}ms", color=discord.Color.random(), timestamp=datetime.datetime.utcnow())
    pembed.set_footer(text=f"{botver} by Sushka_#5709")
    await ctx.send('Ping Pong!', hidden=True)
    await ctx.send(embed=pembed)

@commands.has_permissions(administrator=True)
@slash.subcommand(base='db', name='make', description='Command to make the database for user notes.', guild_ids=guild_ids)
async def make(ctx):
    database = sqlite3.connect('user_notes.db')
    c = database.cursor()
    c.execute(f'''CREATE TABLE user_notes (user_ids text, usernames text, notes text, friend_code text, sex)''')
    database.commit()
    database.close()
    await ctx.send('Database has been created!', hidden=False)
    channel = discord.utils.get(noter.get_all_channels(), name='general')
    await ctx.send("Bot is back up!", hidden=False)

@slash.subcommand(base='note', name='add', description='Adds a user id with a note to the database.', guild_ids=guild_ids)
async def add(ctx, user_id: str, user_name: str, note: str, friend_code: str, sex: str):
    database = sqlite3.connect('user_notes.db')
    c = database.cursor()
    c.execute(f"INSERT INTO user_notes VALUES ('{user_id}', '{user_name}', '{note}', '{friend_code}', '{sex}')")
    database.commit()
    database.close()
    await ctx.send('User and note successfully added!', hidden=True)

@commands.has_permissions(administrator=True)
@slash.subcommand(base='note', name='rmv', description='Removes a user and their note from the database.', guild_ids=guild_ids)
async def rmv(ctx, user_id: str):
    if not user_id.isdigit():
        embed = discord.Embed(title="**OOPS**", description="You must provide a user ID to add!", colour=0xe0cd00, timestamp=datetime.datetime.utcnow())
        embed.set_footer(text=f"{botver} by Sushka_#5709")
        await ctx.send(embed=embed, delete_after=15)
    else:
        database = sqlite3.connect('user_notes.db')
        c = database.cursor()
        c.execute(f"DELETE FROM user_notes WHERE user_ids LIKE '{user_id}'")
        database.commit()
        database.close()
        await ctx.send('User and note successfully removed!', hidden=True)


@slash.subcommand(base='note', name='show', description='Adds a user id with a note to the database.', guild_ids=guild_ids)
async def show(ctx, user_id: str):
    database = sqlite3.connect('user_notes.db')
    c = database.cursor()
    c.execute(f"SELECT user_ids FROM user_notes WHERE user_ids = '{user_id}' ")
    user = c.fetchone()

    if not user:
        embed = discord.Embed(title="**❌ Error ❌**", description=f"No user with ID of `{user_id}` can be found in the database.", colour=0xff0000, timestamp=datetime.datetime.utcnow())
        embed.set_footer(text=f"{botver} by Sushka_#5709")
        await ctx.send(embed=embed)
    else:
        c.execute(f"SELECT user_ids FROM user_notes WHERE user_ids = '{user_id}'")
        u_id = c.fetchone()
        c.execute(f"SELECT usernames FROM user_notes WHERE user_ids = '{user_id}'")
        name = c.fetchone()
        c.execute(f"SELECT notes FROM user_notes WHERE user_ids = '{user_id}'")
        note = c.fetchone()
        c.execute(f"SELECT friend_code FROM user_notes WHERE user_ids = '{user_id}'")
        friend_code = c.fetchone()
        c.execute(f"SELECT sex FROM user_notes WHERE user_ids = '{user_id}'")
        sex = c.fetchone()
        c.close()
        embed = discord.Embed(title=f"__**Notes about user '{user_id}'!**__", colour=0x941db4, timestamp=datetime.datetime.utcnow())
        embed.set_thumbnail(url='https://cdn.discordapp.com/avatars/591665811484049429/9e3054188305485285ac092157ffe6a1.png?size=128')
        embed.add_field(name='User_id: ', value=f'`{u_id[0]}`', inline=True)
        embed.add_field(name='Username: ', value=f'`{name[0]}`', inline=True)
        embed.add_field(name='Note: ', value=f'`{note[0]}`', inline=False)
        embed.add_field(name='friend_code: ', value=f'`{friend_code[0]}`', inline=False)
        embed.add_field(name='sex: ', value=f'`{sex[0]}`', inline=False)
        embed.set_footer(text=f"{botver} by Sushka_#5709", icon_url='https://cdn.discordapp.com/avatars/591665811484049429/9e3054188305485285ac092157ffe6a1.png?size=128')
        await ctx.send(embed=embed)

noter.run(TOKEN)

Когда я прочитал документацию, то подумал, что чтобы ограничить бота, нужно добавить данный кусок когда в самое начало -

@noter.event
async def on_message(message):
    if int(message.channel.id) != 818865123204005899:
        return

Но у бота все равно остается доступ ко всем чатам. как это исправить?


Ответы (0 шт):