#Music Bot.

1 messages · Page 1 of 1 (latest)

civic forum
#

TabError: inconsistent use of tabs and spaces in indentation
lol

#

Tabfehler: Inkonsistente Verwendung von Tabulatoren und Leerzeichen beim Einzug

olive anchor
#

Error is pretty much self explanatory

open fog
#

ja den habe ich behoben bekommen jetzt kommt aber folgendes:

dc@vmd115250:~/bot$ python3 main.py
main.py:18: RuntimeWarning: coroutine 'BotBase.add_cog' was never awaited
bot.add_cog(help_cog(bot))
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
main.py:19: RuntimeWarning: coroutine 'BotBase.add_cog' was never awaited
bot.add_cog(music_cog(bot))
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
2023-07-06 18:20:45 INFO discord.client logging in using static token
Traceback (most recent call last):
File "main.py", line 22, in <module>
File "/home/dc/.local/lib/python3.8/site-packages/discord/client.py", line 860, in run
asyncio.run(runner())
File "/usr/lib/python3.8/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
return future.result()
File "/home/dc/.local/lib/python3.8/site-packages/discord/client.py", line 849, in runner
await self.start(token, reconnect=reconnect)
File "/home/dc/.local/lib/python3.8/site-packages/discord/client.py", line 777, in start
await self.login(token)
File "/home/dc/.local/lib/python3.8/site-packages/discord/client.py", line 609, in login
raise TypeError(f'expected token to be a str, received {token.class.name} instead')
TypeError: expected token to be a str, received NoneType instead
dc@vmd115250:~/bot$

civic forum
#

TypeError: expected token to be a str, received NoneType instead

#

Bot can't get token

olive anchor
#

My man can't read errors

civic forum
open fog
civic forum
#

bot.run(os.getenv("token"))

#

Add token to your env

wide lake
#

Also pls dont use "/" as a prefix with commands.Bot()

open fog
#

in welches verzeichniss muss die .env datei rein ?

wide lake
open fog
#

ich habe sie direckt im selben Ordner wie die Main

#

aber es geht nicht

open fog
wide lake
#

from dotenv import load_dotenv

open fog
wide lake
#

Ändere es zu discord.Bot wenn du nur noch slash_commands Benutzt

#

Und entferne das mit dem prefix bei discord.Bot

open fog
#

äh wie soll das dann heißen ?

wide lake
#

Benutzt du nur slash commands?

open fog
#

also ich möchte das alle Commands mit "-" beginnen

#

oder !

wide lake
#

Also dann brauchst du intents

open fog
#

okay und wie würde ich das machen?

open fog
# wide lake Also dann brauchst du intents

Was soll das jetzt heißen?

dc@vmd115250:~/bot$ python3 main.py
main.py:19: RuntimeWarning: coroutine 'BotBase.add_cog' was never awaited
bot.add_cog(help_cog(bot))
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
main.py:20: RuntimeWarning: coroutine 'BotBase.add_cog' was never awaited
bot.add_cog(music_cog(bot))
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
dc@vmd115250:~/bot$

wide lake
#

kommt es immer noch, wenn du load_extensions("") benutzt?

open fog
# wide lake kommt es immer noch, wenn du load_extensions("") benutzt?

so sieht die main jetzt aus

GNU nano 4.8 main.py
import discord
from discord.ext import commands
import os

#import all of the cogs
from help_cog import help_cog
from music_cog import music_cog

from dotenv import load_dotenv

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

#remove the default help command so that we can write out own
bot.remove_command('help')

#register the class with the bot
bot.add_cog(help_cog(bot))
bot.add_cog(music_cog(bot))

#start the bot with our token
token = str(os.getenv("TOKEN"))

wide lake
#

Du musst es nicht importieren, wenn du bot.load_extension benutzt

open fog
wide lake
#

bot.load_extension("name")

open fog
wide lake
#

bot.add_cog

open fog
#

aber den bot add brauche ich ndoch für die music befehle

#

oder nicht

wide lake
open fog
wide lake
#

von der Datei

open fog
wide lake
#

versuch es

open fog
# wide lake versuch es

kommt das

dc@vmd115250:~/bot$ python3 main.py
main.py:20: RuntimeWarning: coroutine 'BotBase.load_extension' was never awaited
bot.load_extension("help_cog")
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
main.py:21: RuntimeWarning: coroutine 'BotBase.load_extension' was never awaited
bot.load_extension("music_cog")
RuntimeWarning: Enable tracemalloc to get the object allocation traceback

open fog
#

dc@vmd115250:~/bot$ pip list
Package Version


aiohttp 3.8.4
aiosignal 1.3.1
async-timeout 4.0.2
attrs 23.1.0
certifi 2019.11.28
chardet 3.0.4
charset-normalizer 3.1.0
colorama 0.4.6
command-not-found 0.3
dbus-python 1.2.16
discord 2.3.1
discord.py 2.3.1
distro 1.4.0
distro-info 0.23ubuntu1
ezcord 0.1.4
frozenlist 1.3.3
idna 2.8
language-selector 0.1
multidict 6.0.4
netifaces 0.10.4
pip 20.0.2
py-cord 2.4.1
PyGObject 3.36.0
pymacaroons 0.13.0
PyNaCl 1.3.0
python-apt 2.0.1+ubuntu0.20.4.1
python-dotenv 1.0.0
PyYAML 5.3.1
requests 2.22.0
setuptools 45.2.0
six 1.14.0
ssh-import-id 5.10
typing-extensions 4.7.1
ubuntu-advantage-tools 8001
ufw 0.36
urllib3 1.25.8
wheel 0.34.2
yarl 1.9.2
youtube-dl 2021.12.17
dc@vmd115250:~/bot$

wide lake
#

discord.py, discord, py-cord und ezcord deinstallieren und nur py-cord installieren

cursive gate
open fog
#

wie kann ich die am besten dieinstallieren

wide lake
#

Das ist basic Python?

open fog
#

ja

cursive gate
#

.tag learnpython

tranquil vectorBOT
#
open fog
wide lake
#

Dann versuch es nochmal

open fog
#

kommt das Traceback (most recent call last):
File "/home/dc/.local/lib/python3.8/site-packages/discord/cog.py", line 780, in _load_from_module_spec
setup = getattr(lib, "setup")
AttributeError: module 'help_cog' has no attribute 'setup'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "main.py", line 20, in <module>
bot.load_extension("help_cog")
File "/home/dc/.local/lib/python3.8/site-packages/discord/cog.py", line 910, in load_extension
self._load_from_module_spec(spec, name)
File "/home/dc/.local/lib/python3.8/site-packages/discord/cog.py", line 783, in _load_from_module_spec
raise errors.NoEntryPointError(key)
discord.errors.NoEntryPointError: Extension 'help_cog' has no 'setup' function.

wide lake
#

ach, du hast nichtmal richtige cogs erstellt

open fog
wide lake
open fog
# wide lake https://guide.pycord.dev/popular-topics/cogs

ist das nicht daas hier ?

              ```await self.play_music(ctx)

@commands.command(name="pause", help="Pauses the current song being played")
async def pause(self, ctx, *args):
    if self.is_playing:
                    self.is_playing = False
                    self.is_paused = True
                    self.vc.pause()
    elif self.is_paused:
            self.is_paused = False
            self.is_playing = True
            self.vc.resume()

@commands.command(name = "resume", aliases=["r"], help="Resumes playing with the discord bot")
async def resume(self, ctx, *args):
    if self.is_paused:
            self.is_paused = False
            self.is_playing = True
            self.vc.resume()

@commands.command(name="skip", aliases=["s"], help="Skips the current song being played")
async def skip(self, ctx):
    if self.vc != None and self.vc:
        self.vc.stop()
        #try to play next in the queue if it exists
        await self.play_music(ctx)


@commands.command(name="queue", aliases=["q"], help="Displays the current songs in queue")
async def queue(self, ctx):
    retval = ""
    for i in range(0, len(self.music_queue)):
        # display a max of 5 songs in the current queue
        if (i > 4): break
        retval += self.music_queue[i][0]['title'] + "\n"

    if retval != "":
        await ctx.send(retval)
    else:
        await ctx.send("No music in queue")

@commands.command(name="clear", aliases=["c", "bin"], help="Stops the music and clears the queue")
async def clear(self, ctx):
    if self.vc != None and self.is_playing:
        self.vc.stop()
    self.music_queue = []
    await ctx.send("Music queue cleared")

@commands.command(name="leave", aliases=["disconnect", "l", "d"], help="Kick the bot from VC")
async def dc(self, ctx):
    self.is_playing = False
    self.is_paused = False
    await self.vc.disconnect()```
olive anchor
#

They look like cog commands

#

They're using self in functions.

open fog
oak coral
#

.tag codeblock

tranquil vectorBOT
#

Please put your code in a code block:
```py
Here is your Code
```

That makes reading code in Discord a lot easier:

print("This is an example.")
wide lake
open fog
#

ja wie oben gefragt ist das nicht das was ich in einer anderen datei stehen habe?

wide lake
#

Es fehlt die Klasse und so weiter

open fog
open fog
# wide lake wie das bei dem link

wenn ich die beiden vergleiche fehlt folgendes

def setup(bot): # this is called by Pycord to setup the cog
bot.add_cog(Greetings(bot)) # add the cog to the bot

bot.load_extension('cogs.greetings')

cogs_list = [
'greetings',
'moderation',
'fun',
'owner'
]

for cog in cogs_list:
bot.load_extension(f'cogs.{cog}')

wide lake
#

?

#

Das bei dem Link sind die Datein mit den cogs, von der Main Datei würdest du diese laden

open fog
# wide lake ?

also muss das einfach in die main datei eingeführt werden

wide lake
#

Das mit der Klasse kommt in den cog

open fog
#

ich kann dir aktuell nicht folgen, was du mit Klassen meinst

wide lake
#

Damit hast du bestätigt, dass du kein basic Python kannst

#

Das ist eine Klasse

open fog
#

ja die sind ja in der anderen Datei drinne

#

und die müssen in die Main datei

open fog
#

Jetzt das soweit geklappt nur das jetzt folgendes kommt

Traceback (most recent call last):
File "main.py", line 19, in <module>
bot.run(os.getenv("MYTOKEN"))
File "/home/dc/.local/lib/python3.8/site-packages/discord/client.py", line 717, in run
return future.result()
File "/home/dc/.local/lib/python3.8/site-packages/discord/client.py", line 696, in runner
await self.start(*args, **kwargs)
File "/home/dc/.local/lib/python3.8/site-packages/discord/client.py", line 659, in start
await self.login(token)
File "/home/dc/.local/lib/python3.8/site-packages/discord/client.py", line 509, in login
raise TypeError(
TypeError: token must be of type str, not NoneType

wide lake
#

Das erklärt sich von selbst