-
Notifications
You must be signed in to change notification settings - Fork 30
Discord Bot
Kain edited this page Jul 21, 2022
·
3 revisions
Below is a very, very simple example on how to use this package in a Discord Bot.
TypeScript
import { Client, Intents, Message } from 'discord.js';
import { youtube } from 'scrape-youtube';
const client = new Client({ intents: Intents.FLAGS.GUILD_MESSAGES });
const prefix = '~';
client.on('message', (message: Message) => {
if (!message.content.startsWith(prefix)) return;
const args = message.content.split(' ');
const cmd = args.shift().replace(prefix, '');
if (cmd === 'youtube') {
const { videos } = await youtube.search(args.join(' '));
if (videos.length) message.channel.send('Here you go:\n' + videos[0].link);
else message.channel.send('No results for that query');
}
});
client.login('token');
JavaScript
const Discord = require('discord.js');
const { youtube } = require('scrape-youtube');
const client = new Discord.Client({ intents: Discord.Intents.FLAGS.GUILD_MESSAGES });
const prefix = '~';
client.on('message', (message) => {
if (!message.content.startsWith(prefix)) return;
const args = message.content.split(' ');
const cmd = args.shift().replace(prefix, '');
if (cmd === 'youtube') {
const { videos } = await youtube.search(args.join(' '));
if (videos.length) message.channel.send('Here you go:\n' + videos[0].link);
else message.channel.send('No results for that query');
}
});
client.login('token');