feat: Add discord commands

Former-commit-id: ef62cb3819e3a5ec4ce2b47fd5f07a5ab8e4cc05
pull/160/head
Zack 2 years ago
parent bea2b6e62b
commit 26ad3e6fb6

@ -1,10 +1,23 @@
import discord
from discord.ext import commands from discord.ext import commands
from swarms.models import OpenAIChat from swarms.models import OpenAIChat
from swarms.agents import OmniModalAgent from swarms.agents import OmniModalAgent
import os
from dotenv import load_dotenv
from discord.ext import commands
load_dotenv()
intents = discord.Intents.default()
intents.messages = True
intents.guilds = True
intents.voice_states = True
intents.message_content = True
bot = commands.Bot(command_prefix="!", intents=intents)
# Setup # Setup
TOKEN = "YOUR_DISCORD_BOT_TOKEN"
bot = commands.Bot(command_prefix="!") DISCORD_TOKEN = os.getenv("DISCORD_TOKEN")
# Initialize the OmniModalAgent # Initialize the OmniModalAgent
llm = OpenAIChat(model_name="gpt-4") llm = OpenAIChat(model_name="gpt-4")
@ -41,5 +54,39 @@ async def help_me(ctx):
""" """
await ctx.send(help_text) await ctx.send(help_text)
@bot.event
async def on_command_error(ctx, error):
"""Handles errors that occur while executing commands."""
if isinstance(error, commands.CommandNotFound):
await ctx.send("That command does not exist!")
else:
await ctx.send(f"An error occurred: {error}")
def setup(bot):
@bot.command()
async def join(ctx):
"""Joins the voice channel that the user is in."""
if ctx.author.voice:
channel = ctx.author.voice.channel
await channel.connect()
else:
await ctx.send("You are not in a voice channel!")
@bot.command()
async def leave(ctx):
"""Leaves the voice channel that the bot is in."""
if ctx.voice_client:
await ctx.voice_client.disconnect()
else:
await ctx.send("I am not in a voice channel!")
# voice_transcription.py
from discord.ext import commands
def setup(bot):
@bot.command()
async def listen(ctx):
"""Starts listening to voice in the voice channel that the bot is in."""
# ... (code for listening to voice and transcribing it goes here)
bot.run(TOKEN) bot.run("DISCORD_TOKEN")

Loading…
Cancel
Save