Coder Social home page Coder Social logo

plon / bard-discord-bot Goto Github PK

View Code? Open in Web Editor NEW
36.0 7.0 14.0 47 KB

Integrate Google Bard into your own discord chatbot

License: GNU General Public License v2.0

Python 100.00%
bard chatbot discord discord-bot discord-chatbot google googlebard discord-py google-bard discord-api

bard-discord-bot's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

bard-discord-bot's Issues

RuntimeWarning: coroutine 'AsyncChatbot.create' was never awaited

Im using the library GoogleBard (implementing bard to my bot as a cog) and i got this error:

  File "/home/tjf1/.local/lib/python3.10/site-packages/discord/ext/commands/core.py", line 235, in wrapped
    ret = await coro(*args, **kwargs)
  File "/home/tjf1/xyzai/xyz.ai/main/cogs/ai.py", line 16, in ask
    response = await Chatbot(BARD_TOKEN).ask(prompt)
  File "/home/tjf1/.local/lib/python3.10/site-packages/Bard.py", line 63, in __init__
    self.async_chatbot = self.loop.run_until_complete(
  File "/usr/lib/python3.10/asyncio/base_events.py", line 622, in run_until_complete
    self._check_running()
  File "/usr/lib/python3.10/asyncio/base_events.py", line 582, in _check_running
    raise RuntimeError('This event loop is already running')
RuntimeError: This event loop is already running

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/tjf1/.local/lib/python3.10/site-packages/discord/ext/commands/bot.py", line 1350, in invoke
    await ctx.command.invoke(ctx)
  File "/home/tjf1/.local/lib/python3.10/site-packages/discord/ext/commands/core.py", line 1029, in invoke
    await injected(*ctx.args, **ctx.kwargs)  # type: ignore
  File "/home/tjf1/.local/lib/python3.10/site-packages/discord/ext/commands/core.py", line 244, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: RuntimeError: This event loop is already running```

couldn't generate a response

so i thought i would give it a shot but as soon as I started testing the bot it just keeps giving me this error below and it also says "i couldn't generate a response" and then some random letters (i think they are not random tho but they are just the couldn't generate a response error

Bot not starting (AttributeError: 'Bot' object has no attribute 'tree')

Hello,
if i want to start the main.py file i get this error:

Traceback (most recent call last):
File "C:\Users[xxx]\Bard-Discord-bot-main\main.py", line 25, in
@bot.tree.command(name="reset", description="Reset chat context")
AttributeError: 'Bot' object has no attribute 'tree'

How could i fix this?

/reset command throwing exception and failing to complete

[2023-05-15 19:52:34] [ERROR ] discord.ext.commands.bot: Ignoring exception in command reset
Traceback (most recent call last):
File "C:\Users\Administrator\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\app_commands\commands.py", line 842, in _do_call
return await self.callback(interaction, **params) # type: ignore
File "C:\Bard-Discord-bot\main.py", line 111, in reset
await ctx.send("Bot context has been reset.")
File "C:\Users\Administrator\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\ext\commands\context.py", line 884, in send
await self.interaction.response.send_message(**kwargs)
File "C:\Users\Administrator\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\interactions.py", line 778, in send_message
await adapter.create_interaction_response(
File "C:\Users\Administrator\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\webhook\async
.py", line 219, in request
raise NotFound(response, data)
discord.errors.NotFound: 404 Not Found (error code: 10062): Unknown interaction

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "C:\Users\Administrator\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\ext\commands\hybrid.py", line 438, in _invoke_with_namespace
value = await self._do_call(ctx, ctx.kwargs) # type: ignore
File "C:\Users\Administrator\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\app_commands\commands.py", line 860, in _do_call
raise CommandInvokeError(self, e) from e
discord.app_commands.errors.CommandInvokeError: Command 'reset' raised an exception: NotFound: 404 Not Found (error code: 10062): Unknown interaction

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "C:\Users\Administrator\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\ext\commands\hybrid.py", line 438, in _invoke_with_namespace
value = await self._do_call(ctx, ctx.kwargs) # type: ignore
File "C:\Users\Administrator\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\app_commands\commands.py", line 860, in _do_call
raise CommandInvokeError(self, e) from e
discord.ext.commands.errors.HybridCommandError: Hybrid command raised an error: Command 'reset' raised an exception: NotFound: 404 Not Found (error code: 10062): Unknown interaction

Bard not responding

What do I do with the copy of the __Secure-1PSID cookie? My bard bot has joined but will not type back. I tried putting it in the config bard token field with no luck.

Exception while using /chat

I did a git pull / and ran pip3 install for the updated requirements.txt, and am getting an exception when I try to use the chat command:

[2023-06-04 18:38:18] [ERROR ] discord.app_commands.tree: Ignoring exception in command 'chat'
Traceback (most recent call last):
File "C:\Users\Administrator\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\app_commands\commands.py", line 842, in _do_call
return await self._callback(interaction, **params) # type: ignore
File "C:\Bard-Discord-bot\main.py", line 176, in chat
response = await generate_response(message)
File "C:\Bard-Discord-bot\main.py", line 38, in generate_response
response = bard.ask(prompt)
File "C:\Users\Administrator\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\Bard.py", line 83, in ask
return self.loop.run_until_complete(self.async_chatbot.ask(message))
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.3056.0_x64__qbz5n2kfra8p0\lib\asyncio\base_events.py", line 625, in run_until_complete
self._check_running()
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.3056.0_x64__qbz5n2kfra8p0\lib\asyncio\base_events.py", line 586, in _check_running
raise RuntimeError(
RuntimeError: Cannot run the event loop while another loop is running

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "C:\Users\Administrator\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\app_commands\tree.py", line 1248, in _call
await command._invoke_with_namespace(interaction, namespace)
File "C:\Users\Administrator\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\app_commands\commands.py", line 867, in _invoke_with_namespace
return await self._do_call(interaction, transformed_values)
File "C:\Users\Administrator\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\app_commands\commands.py", line 860, in _do_call
raise CommandInvokeError(self, e) from e
discord.app_commands.errors.CommandInvokeError: Command 'chat' raised an exception: RuntimeError: Cannot run the event loop while another loop is running
C:\Users\Administrator\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\app_commands\tree.py:1252: RuntimeWarning: coroutine 'AsyncChatbot.ask' was never awaited
await self.on_error(interaction, e)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback

use the example code from README result >>> chatbot = Chatbot(token) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/ubuntu/test/venv/lib/python3.11/site-packages/Bard.py", line 63, in __init__ self.async_chatbot = self.loop.run_until_complete( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete return future.result() ^^^^^^^^^^^^^^^ File "/home/ubuntu/test/venv/lib/python3.11/site-packages/Bard.py", line 143, in create instance.SNlM0e = await instance.__get_snlm0e() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/ubuntu/test/venv/lib/python3.11/site-packages/Bard.py", line 196, in __get_snlm0e raise Exception( Exception: Response code not 200. Response Status is 302

Screenshot_2023_0610_114109.jpg

This issue.

Exception when using /chat command

If I try something short like "/chat testing123" it works, but if I try a sentence like "/chat What about longer sentences?" and "/chat is it because of the question mark", both fail.

[2023-05-18 15:53:14] [ERROR ] discord.app_commands.tree: Ignoring exception in command 'chat'
Traceback (most recent call last):
File "C:\Users\Administrator\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\app_commands\commands.py", line 842, in _do_call
return await self.callback(interaction, **params) # type: ignore
File "C:\Bard-Discord-bot\main.py", line 139, in chat
await interaction.response.send_message(interaction_response, allowed_mentions=allowed_mentions)
File "C:\Users\Administrator\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\interactions.py", line 778, in send_message
await adapter.create_interaction_response(
File "C:\Users\Administrator\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\webhook\async
.py", line 219, in request
raise NotFound(response, data)
discord.errors.NotFound: 404 Not Found (error code: 10062): Unknown interaction

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "C:\Users\Administrator\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\app_commands\tree.py", line 1248, in _call
await command._invoke_with_namespace(interaction, namespace)
File "C:\Users\Administrator\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\app_commands\commands.py", line 867, in _invoke_with_namespace
return await self._do_call(interaction, transformed_values)
File "C:\Users\Administrator\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\app_commands\commands.py", line 860, in _do_call
raise CommandInvokeError(self, e) from e
discord.app_commands.errors.CommandInvokeError: Command 'chat' raised an exception: NotFound: 404 Not Found (error code: 10062): Unknown interaction

Error when launching bot that indicates a privileged intent is being requested that was not enabled - I have enabled "message content" intent in discord developer portal

Title says it all - here is the info from console.

Traceback (most recent call last):
File "C:\Bard-Discord-bot\main.py", line 130, in
bot.run(TOKEN)
File "C:\Users\Administrator\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\client.py", line 860, in run
asyncio.run(runner())
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.3056.0_x64__qbz5n2kfra8p0\lib\asyncio\runners.py", line 44, in run
return loop.run_until_complete(main)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.3056.0_x64__qbz5n2kfra8p0\lib\asyncio\base_events.py", line 649, in run_until_complete
return future.result()
File "C:\Users\Administrator\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\client.py", line 849, in runner
await self.start(token, reconnect=reconnect)
File "C:\Users\Administrator\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\client.py", line 778, in start
await self.connect(reconnect=reconnect)
File "C:\Users\Administrator\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\client.py", line 704, in connect
raise PrivilegedIntentsRequired(exc.shard_id) from None
discord.errors.PrivilegedIntentsRequired: Shard ID None is requesting privileged intents that have not been explicitly enabled in the developer portal. It is recommended to go to https://discord.com/developers/applications/ and explicitly enable the privileged intents within your application's page. If this is not possible, then consider disabling the privileged intents instead.

Thanks!

Exception stating "cannot send an empty message" when using /chat

A User was chatting with the bot and it generated an exception. See screenshot and exception:

Screenshot 2023-05-18 171926

[2023-05-18 16:33:45] [ERROR ] discord.app_commands.tree: Ignoring exception in command 'chat'
Traceback (most recent call last):
File "C:\Users\Administrator\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\app_commands\commands.py", line 842, in _do_call
return await self._callback(interaction, **params) # type: ignore
File "C:\Bard-Discord-bot\main.py", line 140, in chat
await interaction.channel.send(chunk)
File "C:\Users\Administrator\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\abc.py", line 1561, in send
data = await state.http.send_message(channel.id, params=params)
File "C:\Users\Administrator\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\http.py", line 744, in request
raise HTTPException(response, data)
discord.errors.HTTPException: 400 Bad Request (error code: 50006): Cannot send an empty message

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "C:\Users\Administrator\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\app_commands\tree.py", line 1248, in _call
await command._invoke_with_namespace(interaction, namespace)
File "C:\Users\Administrator\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\app_commands\commands.py", line 867, in _invoke_with_namespace
return await self._do_call(interaction, transformed_values)
File "C:\Users\Administrator\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\app_commands\commands.py", line 860, in _do_call
raise CommandInvokeError(self, e) from e
discord.app_commands.errors.CommandInvokeError: Command 'chat' raised an exception: HTTPException: 400 Bad Request (error code: 50006): Cannot send an empty message

No Responses

The bot keep thinking without sending response to /chat and there isnt errors

Help no response

I put the right bard token, I'm hosting the bot on host provider but the bot still doesn't response to my messages, pls help

error while starting the bot

@bot.hybrid_command(name="toggledm", description="Toggle DM for chatting.")
AttributeError: 'Bot' object has no attribute 'hybrid_command'

followed all the steps correctly but getting this error

/help command issue

/help command doesnt work and great work:)
other commands working good thanks, but i hope i can make replyall work in 1 channel only, like byy adding channel id in the code or mention channel by command or something possible for that

Returned message format

Thank you for this project! It's a great bot.

I have an issue request. The return message from bard is coming through as one long paragraph. Example below.

Can it please be formatted to return the message in paragraph format?

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.