discord server bot der musik abspielt die auf dem pc gespeichert ist?

guten frühen morgen

ich habe einen server der 24/7 an ist und habe dc drauf gemacht (system: windows 10), habe es micht chat gpt versucht das dass mir das erklärt, hat aber nicht funktioniert. daher frage ich hir mal nach. ich bin die ganze zeit daren stehen geblieben wenn ich den in den chat !join (damit der den sprach chat brtritt(der bot ist auch auf dem server hinzugefügt mit den passenden berechtigungen)) reagirt der nicht, es passiert garnix. kann mir bitte jemand helfen.

hir ist den pyton code:

import discord

from discord.ext import commands

import os

intents = discord.Intents.default()

intents.voice_states = True

intents.messages = True # Falls du auch auf Nachrichten reagieren möchtest

bot = commands.Bot(command_prefix='!', intents=intents)

@bot.event

async def on_ready():

   print(f'We have logged in as {bot.user}')

@bot.command(name='!join', help='Tritt einem Sprachkanal bei')

async def join(ctx):

   if ctx.author.voice:

       channel = ctx.author.voice.channel

       await channel.connect()

@bot.command(name='!leave', help='Verlässt den Sprachkanal')

async def leave(ctx):

   if ctx.voice_client:

       await ctx.guild.voice_client.disconnect()

@bot.command(name='!play', help='Spielt Musik ab')

async def play(ctx, *, query):

   if ctx.voice_client:

       source = discord.FFmpegPCMAudio(query)

       ctx.voice_client.play(source)

@bot.command(name='!stop', help='Stoppt die Musik')

async def stop(ctx):

   if ctx.voice_client:

       ctx.voice_client.stop()

bot.run (' das token ist auch richtig ')

MFG nick

Bot, Discord Server, Discord Bot
Python Fehlermeldung "KeyError: 'data'"?

Ich möchte gerne einen KI Discord Server machen. Die KI hab ich schon und diese hat auch eine API(?). Ich hab den Bot auch schon auf dem Server und ich kann auch Prompts eingeben. Aber wenn ich Prompt eingebe, kommt bei diesem Code:

import discord
from gradio_client import Client


TOKEN = 'MeinToken'
FOOOCUS_API_URL = 'http://127.0.0.1:7865/'


fooocus_client = Client(FOOOCUS_API_URL)


intents = discord.Intents.default()
client = discord.Client(intents=intents)


@client.event
async def on_ready():
    print(f'{client.user} ist eingeloggt!')


@client.event
async def on_message(message):
    if message.channel.name == 'prompt-kanal' and message.author != client.user:
        result = fooocus_client.predict(message.content, fn_index=2)
        await message.channel.send(file=discord.File(result))


client.run(TOKEN)

Diese Fehlermeldung:

2024-04-16 15:35:07 ERROR discord.client Ignoring exception in on_message
Traceback (most recent call last):
File "C:...\venv\Lib\site-packages\gradio_client\compatibility.py", line 105, in _predict
output = result["data"]
~~~~~~^^^^^^^^
KeyError: 'data'

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

Traceback (most recent call last):
File "C:...\venv\Lib\site-packages\discord\client.py", line 441, in _run_event
await coro(*args, **kwargs)
File "c:...\bot.py", line 19, in on_message
result = fooocus_client.predict(message.content, fn_index=2)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:...\venv\Lib\site-packages\gradio_client\client.py", line 459, in predict
).result()
^^^^^^^^
File "C:...\venv\Lib\site-packages\gradio_client\client.py", line 1374, in result
return super().result(timeout=timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users..._base.py", line 456, in result
return self.__get_result()
^^^^^^^^^^^^^^^^^^^
File "C:\Users..._base.py", line 401, in __get_result
raise self._exception
File "C:\Users...\thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:...\compatibility.py", line 65, in _inner
predictions = _predict(*data)
^^^^^^^^^^^^^^^
File "C:...\compatibility.py", line 119, in _predict
raise KeyError(
KeyError: 'Could not find 'data' key in response. Response received: {'detail': [{'type': 'model_attributes_type', 'loc': ['body'], 'msg': 'Input should be a valid dictionary or object to extract fields from', 'input': '{"data": [""], "fn_index": 2, "session_hash": "d7f62bf0-174c-45fe-b3f6-c5e7f00848d3"}', 'url': 'https://errors.pydantic.dev/2.1/v/model_attributes_type'}]}'

Ich checke einfach nicht, woran das liegen könnte...

Linux, Bot, cmd, Code, künstliche Intelligenz, Programmiersprache, Python, Python 3, Pycharm, Discord, Discord Bot, ChatGPT
Code zentralisieren?

Kann mir jemand helfen meinen Code zu zentralisieren? Ich möchte die DB connection aus dem code raus gezogen wird danke.

const fs = require('node:fs');
const path = require('node:path');
const { Client, Collection, Events, GatewayIntentBits } = require('discord.js');
const { token } = require('./config.json');
const { Sequelize } = require('sequelize');
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
const sequelize = new Sequelize({
dialect: 'sqlite',
storage: ''
});
client.commands = new Collection();
const foldersPath = path.join(__dirname, 'commands');
const commandFolders = fs.readdirSync(foldersPath);
for (const folder of commandFolders) {
const commandsPath = path.join(foldersPath, folder);
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
if ('data' in command && 'execute' in command) {
client.commands.set(command.data.name, command);
} else {
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}
}
const eventsPath = path.join(__dirname, 'events');
const eventFiles = fs.readdirSync(eventsPath).filter(file => file.endsWith('.js'));
for (const file of eventFiles) {
const filePath = path.join(eventsPath, file);
const event = require(filePath);
if (event.once) {
client.once(event.name, (...args) => event.execute(...args));
} else {
client.on(event.name, (...args) => event.execute(...args));
}
}
(async () => {
try {
await sequelize.authenticate();
console.log('The connection to the database has been successfully established.');
} catch (error) {
console.error('The connection to the database has failed:', error);
} finally {
sequelize.close();
}
})();
client.login(token);
JavaScript, Code, Programmiersprache, Environment, node.js, Discord, Discord Bot

Meistgelesene Beiträge zum Thema Discord Bot