Giter Club home page Giter Club logo

Comments (10)

Xx-Mohit-xX avatar Xx-Mohit-xX commented on August 17, 2024 1

Since it doesn't look like there's an option for that built in yt-search,
you can use bad-words-npm

It will replace all bad words specified with **
(or whatever you want to set the placeholder to)

The thing you specified will replace bad word with ** but i want it to check bad words and return "dont use bad words or something" . I got the idea how to do so.

from youtube-search.

Xx-Mohit-xX avatar Xx-Mohit-xX commented on August 17, 2024

Full code, as you dont have a support

const { CommandInteraction, MessageEmbed } = require("discord.js");
const he = require('he');
const search = require('youtube-search');

module.exports = {
    name: "youtube-search",
    description: "Search youtube for a specific text provided",
    ownerOnly: false,
    options: [
        {
            type: 'STRING',
            description: 'name of video',
            name: 'video',
            required: true,
        },
    ],
    userperm: [""],
    botperm: [""],
    /**
     *
     * @param {CommandInteraction} interaction
     * @param {String[]} args
     */
    run: async (bot, interaction, args) => {
    const apiKey = process.env.YT_KEY
    const videoName = args.join(' ');

    if (!videoName) return interaction.editReply(`${emoji.Error} Please provide a YouTube video name`);

    const searchOptions = { maxResults: 1, key: apiKey, type: 'video', safeSearch: "strict"};

    let result = await search(videoName, searchOptions)
      .catch(err => {
        return interaction.editReply(`${bot.error} Please try again in a few seconds`);
      });

    result = result.results[0];
    if (!result) 
    return interaction.editReply(`${bot.error} Unable to find **${videoName}**, please try a different YT Title`);

    const decodedTitle = he.decode(result.title);
    const embed = new MessageEmbed()
    .setTitle(decodedTitle)
    .setURL(result.link)
    .setThumbnail('https://cdn1.iconfinder.com/data/icons/logotypes/32/youtube-512.png')
    .setDescription(result.description)
    .setFooter(`${interaction.user.username}`, interaction.user.avatarURL({ dynamic: true }))
    .setImage(result.thumbnails.high.url)
    .setTimestamp()
    .setColor(bot.color)

    interaction.editReply({ embeds: [ embed ] })
  }
}

from youtube-search.

Shadowblazer93 avatar Shadowblazer93 commented on August 17, 2024
safeSearch: 'strict'

Replace the "" with ''

The correct syntax would be:

 const searchOptions = { maxResults: 1, key: apiKey, type: 'video', safeSearch: 'strict'};

from youtube-search.

Xx-Mohit-xX avatar Xx-Mohit-xX commented on August 17, 2024

Oky thanks, I'll try

from youtube-search.

Xx-Mohit-xX avatar Xx-Mohit-xX commented on August 17, 2024

Nope still shows nsfw stuff

from youtube-search.

Shadowblazer93 avatar Shadowblazer93 commented on August 17, 2024

Make sure to go into the video and check if it is age-restricted.
Sometimes youtube is dumb and doesn't age-restrict videos.

If you want, here is my code which works flawlessly
(you may need to change some stuff since your setup is a little different)

from youtube-search.

Xx-Mohit-xX avatar Xx-Mohit-xX commented on August 17, 2024

Oky thanks for clearing, so this safefilter only restricts age restricted videoes??

from youtube-search.

Shadowblazer93 avatar Shadowblazer93 commented on August 17, 2024

Yes.
Also, if you want extra security you can blacklist words from the search.

from youtube-search.

Xx-Mohit-xX avatar Xx-Mohit-xX commented on August 17, 2024

Yes. Also, if you want extra security you can blacklist words from the search.

Can you show an example

from youtube-search.

Shadowblazer93 avatar Shadowblazer93 commented on August 17, 2024

Since it doesn't look like there's an option for that built in yt-search,
you can use bad-words-npm

It will replace all bad words specified with **
(or whatever you want to set the placeholder to)

from youtube-search.

Related Issues (20)

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.