Coder Social home page Coder Social logo

image_bot's People

Contributors

alvarorenan avatar fhoxydeo avatar pawel02 avatar

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

Watchers

 avatar  avatar

image_bot's Issues

self.image_names error

self.image_names keeps the names of last search if seconds search is made.

Possible fix: add "self.image_names = []" in update_image() function.

it's crashing

Traceback (most recent call last):
File "D:\code\python\image_bot\main.py", line 18, in
bot.add_cog(image_cog(bot))
File "D:\code\python\image_bot\image_cog.py", line 27, in init
self.update_images()
File "D:\code\python\image_bot\image_cog.py", line 49, in update_images
for filename in os.listdir(self.download_folder):
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'downloads'

Process finished with exit code 1

Import

It shows warning on
from youtube_dl import YouTubeDL
and
When we execute python main.py
It shows no modules found

DvrkWolf issue

#its a music part of my bot. Im Dvrkwolf from your youtube channel

{main.py}

`import discord
from discord.ext import commands
import asyncio
import json
import functools
import itertools
import os
from discord import Embed
from async_timeout import timeout
import random

from main_cog import main_cog
from music_cog import music_cog

intents = discord.Intents.default()
intents.members = True
bot = commands.Bot(command_prefix = "s!", intents=intents)

@bot.event
async def on_member_join(member):
channel = bot.get_channel(id=764897980822061100)
await channel.send(f"{member.mention} joined to the server ! Welcome to the Natus For Better ! Please read the #rules. Have Fun!")
role = discord.utils.get(member.guild.roles,name='π•„π”Όπ•„π”Ήπ”Όβ„π•Š')
await member.add_roles(role)

@bot.event
async def on_member_remove(member):
channel = bot.get_channel(id=764897980822061100)
await channel.send(f"{member.mention} left the server :( ")

@bot.event
async def on_ready():
print('client ready')

bot.add_cog(main_cog(bot))
bot.add_cog(music_cog(bot))

@bot.remove_command("help")

@bot.group(invoke_without_command=True)
async def help(ctx):

em=discord.Embed(tittle = "Help", description = "Use klop for extended information on a command.",color = ctx.author.color)

em.add_field(name = "Moderation", value = "kick,ban,warn")
em.add_field(name = "Fun", value = "slap,ping")

await ctx.send(embed = em)

bot.run("TOKEN")`

{main_cog.py}

`import discord
from discord.ext import commands

class main_cog(commands.Cog):
def init(self, bot):
self.bot = bot
self.help_message = """

General commands:
/help - displays all the available commands
/clear amount - will delete the past messages with the amount specified
Image commands:
/search <keywords> - will change the search to the keyword
/get - will get the image based on the current search
Music commands:
/p <keywords> - finds the song on youtube and plays it in your current channel
/q - displays the current music queue
/skip - skips the current song being played

"""
self.text_channel_list = []`

{music_cog.py}

import discord
from discord.ext import commands

from youtube_dl import YoutubeDL

class music_cog(commands.Cog):
def init(self, bot):
self.bot = bot

    #all the music related stuff
    self.is_playing = False

    # 2d array containing [song, channel]
    self.music_queue = []
    self.YDL_OPTIONS = {'format': 'bestaudio', 'noplaylist':'True'}
    self.FFMPEG_OPTIONS = {'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5', 'options': '-vn'}

    self.vc = ""

 #searching the item on youtube
def search_yt(self, item):
    with YoutubeDL(self.YDL_OPTIONS) as ydl:
        try: 
            info = ydl.extract_info("ytsearch:%s" % item, download=False)['entries'][0]
        except Exception: 
            return False

    return {'source': info['formats'][0]['url'], 'title': info['title']}

def play_next(self):
    if len(self.music_queue) > 0:
        self.is_playing = True

        #get the first url
        m_url = self.music_queue[0][0]['source']

        #remove the first element as you are currently playing it
        self.music_queue.pop(0)

        self.vc.play(discord.FFmpegPCMAudio(m_url, **self.FFMPEG_OPTIONS), after=lambda e: self.play_next())
    else:
        self.is_playing = False

# infinite loop checking 
async def play_music(self):
    if len(self.music_queue) > 0:
        self.is_playing = True

        m_url = self.music_queue[0][0]['source']
        
        #try to connect to voice channel if you are not already connected

        if self.vc == "" or not self.vc.is_connected():
            self.vc = await self.music_queue[0][1].connect()
        else:
            self.vc = await self.bot.move_to(self.music_queue[0][1])
        
        print(self.music_queue)
        #remove the first element as you are currently playing it
        self.music_queue.pop(0)

        self.vc.play(discord.FFmpegPCMAudio(m_url, **self.FFMPEG_OPTIONS), after=lambda e: self.play_next())
    else:
        self.is_playing = False

@commands.command(name="play", help="Plays a selected song from youtube")
async def p(self, ctx, *args):
    query = " ".join(args)
    
    voice_channel = ctx.author.voice.channel
    if voice_channel is None:
        #you need to be connected so that the bot knows where to go
        await ctx.send("Connect to a voice channel!")
    else:
        song = self.search_yt(query)
        if type(song) == type(True):
            await ctx.send("Could not download the song. Incorrect format try another keyword. This could be due to playlist or a livestream format.")
        else:
            await ctx.send("Song added to the queue")
            self.music_queue.append([song, voice_channel])
            
            if self.is_playing == False:
                await self.play_music()

@commands.command(name="queue", help="Displays the current songs in queue")
async def q(self, ctx):
    retval = ""
    for i in range(0, len(self.music_queue)):
        retval += self.music_queue[i][0]['title'] + "\n"

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

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

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.