mirror of
https://github.com/arc53/DocsGPT.git
synced 2026-04-28 13:00:30 +00:00
discord bot fix
Stop random answers
This commit is contained in:
@@ -10,7 +10,7 @@ dotenv.load_dotenv()
|
|||||||
|
|
||||||
# Replace 'YOUR_BOT_TOKEN' with your bot's token
|
# Replace 'YOUR_BOT_TOKEN' with your bot's token
|
||||||
TOKEN = os.getenv("DISCORD_TOKEN")
|
TOKEN = os.getenv("DISCORD_TOKEN")
|
||||||
PREFIX = '@docsgpt '
|
PREFIX = '@DocsGPT'
|
||||||
BASE_API_URL = 'http://localhost:5001'
|
BASE_API_URL = 'http://localhost:5001'
|
||||||
|
|
||||||
intents = discord.Intents.default()
|
intents = discord.Intents.default()
|
||||||
@@ -20,13 +20,11 @@ bot = commands.Bot(command_prefix=PREFIX, intents=intents)
|
|||||||
|
|
||||||
|
|
||||||
def split_string(input_str):
|
def split_string(input_str):
|
||||||
pattern = r'<(.*?)>'
|
pattern = r'^<@!?{0}>\s*'.format(bot.user.id)
|
||||||
match = re.search(pattern, input_str)
|
match = re.match(pattern, input_str)
|
||||||
|
|
||||||
if match:
|
if match:
|
||||||
content = match.group(1)
|
content = input_str[match.end():].strip()
|
||||||
rest = input_str[:match.start()] + input_str[match.end():]
|
return str(bot.user.id), content
|
||||||
return content, rest.strip()
|
|
||||||
return None, input_str
|
return None, input_str
|
||||||
|
|
||||||
|
|
||||||
@@ -59,8 +57,8 @@ async def on_message(message):
|
|||||||
if prefix is None:
|
if prefix is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
part_prefix = "@"
|
part_prefix = str(bot.user.id)
|
||||||
if part_prefix in prefix:
|
if part_prefix == prefix:
|
||||||
answer = await fetch_answer(content)
|
answer = await fetch_answer(content)
|
||||||
await message.channel.send(answer)
|
await message.channel.send(answer)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user