Discord.io - Bot Status - bots

I want to set my discord bot status but I'm using discord.io no discord.js so I can't find some tutorial for me. I tried also watch for discord.js tutorials and try:
bot.user.setPresence({
status: 'online',
game: {
name: '/help'
}
});
Error: It crash after start node bot.js
Or:
bot.on('ready', () => {
bot.user.setGame('/help')
})
Error: Parsing error: Unexpected token )
Can anybody help me please?

I'm writting my code with Visual Studio Code. It seems to have a nice autocomplete feature, and by exploring it a little, I was able to find this tip :
bot.setPresence(
options : { idle_since: any; game: {name: string; type: number; url?: string;}}
): void
I'm not sure what everything means precisely, but most of it seems to be optional. I was for exemple able to change the bot's playing game with :
bot.on('ready', function (evt) {
bot.setPresence( {game: {name:"/help"}} );
});

var name = "with the boys. Built by Ayser & Khalid"
var type = 0;
var url = "https://www.twitch.tv/legendarysharkkk";
bot.setPresence({
game: {
name,
type,
url
}});

Related

REST API with node-rtsp-stream NPM

I am trying to stream a RTSP in HTML5 pages using node-rtsp-stream NPM. Here I can see the live stream in HTML page. But the thing is when I try to do REST API with this it throws TypeError: stream is not a constructor. when I call my post method first time its working properly. when I try to do the same again it throws error.
here is my API:
RTSPRouter.post('/getPreview', (req, res) => {
// stream.mpeg1Muxer.kill();
stream = new stream({
name: 'name',
streamUrl: req.body.RTSPURL,
wsPort: 9999,
ffmpegOptions: {
'-r': 30
}
})
res.send(stream)
})
API for Kill :
RTSPRouter.get('/killPreview', (req, res) => {
process.kill(req.body.pid1)
stream.prototype.stop()// this method also not working
})
Even I killed the stream alone using the PID it's throwing the same error.
Kindly help me to fix this problem, thanks in advance!
you're getting a typeError because you haven't imported Stream.
Your code should look like this:
Stream = require("node-rtsp-stream");
stream = new Stream({
name: "name",
streamUrl: "rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov",
wsPort: 9999,
ffmpegOptions: {
// options ffmpeg flags
"-stats": "", // an option with no neccessary value uses a blank string
"-r": 30, // options with required values specify the value after the key
},
});
res.send(stream);
Also don't forget to run npm install node-rtsp-stream.
After a few days I found the answer for this question.
You should not create stream like this:
var stream = require('node-rtsp-stream')
stream = new stream({
name: 'name',
streamUrl: req.body.RTSPURL,
wsPort: 9999,
ffmpegOptions: {
'-r': 30
}
})
Instead of this, try the below code:
var stream = require('node-rtsp-stream')
var streamObj;
streamObj = new stream({
name: 'name',
streamUrl: req.body.RTSP,
wsPort: 9999,
ffmpegOptions: { // options ffmpeg flags
'-stats': '', // an option with no neccessary value uses a blank string
'-r': 30 // options with required values specify the value after the key
}
})
The actual error is that I had imported a stream with the name stream, and tried to initiate the stream with same variable name stream. You have to use a different variable name to initialize the stream. In my case I used streamobj.

TypeError: Cannot read properties of undefined (reading 'execute') when using module.export

I am trying to split the code for my discord.js bot into multiple js files for better organization and troubleshooting. When doing so, I chained my functions using module.exports linking multiple files together. Going from my index file to the first function file, everything works fine. Going to the second, I get a TypeError said above. I am not sure why this occurs but I think it may have to do with nesting multiple module.export commands?? Is there a solution/alternative to achieve this? I've looked at other questions on this site but I can't seem to find one with the same issue I am facing. Code below.
message.js
module.exports = {
name: 'message',
execute(client, message) {
const{ commandinit } = require(`./commandinit.js`);
if(message.content.startsWith("-") || !message.author.bot) {
var commandObj = message.content.slice(2);
command = commandObj.toLowerCase();
commandinit.execute(client, message, command);
}else{return;}},};
commandinit.js
module.exports = {
name: 'commandinit',
execute(client, message, command){
//do this stuff
},};
Sorry if this is a stupid question, as you can tell I am very new with this. Thanks in advance!

Phaser 3 ScaleManager exception

I am trying to enable fullscreen in my game written in Phaser 3.
I am doing it from Scene class via
this.game.scale.startFullScreen();
but getting error in f12 browser console
Uncaught TypeError: this.game.scale.startFullScreen is not a function
at TitleScene.<anonymous> (TitleScene.js:23)
at InputPlugin.emit (phaser.js:2025)
at InputPlugin.processDownEvents (phaser.js:167273)
...
In docs ScaleManager class has startFullScreen method.
Why console tells me it doesn't?
This is the full code of TitleScene.js:
export class TitleScene extends Phaser.Scene {
constructor ()
{
const config =
{
key: 'TitleScene'
}
super(config);
}
preload ()
{
this.load.image('Title', 'assets/Title.png');
}
create ()
{
this.background = this.add.image(960, 540, 'Title');
this.input.manager.enabled = true;
this.input.once('pointerdown', function () {
this.scene.start('MainScene');
this.game.scale.startFullScreen(); // here is the error
}, this);
}
}
There are two problems prevented me from resolving this problem:
I followed examples from here
https://www.phaser.io/examples/v2
But I am using the third version Phaser. And everyone who uses the same must follow examples from here
https://www.phaser.io/examples/v3
You must pay attention to url while using their site with examples. Both pages are the same from the first look. But urls are different. Also there are warning after each example using the second (old) version of engine.
And finally this function name is not startFullScreen but startFullscreen :)

ReferenceError: mesagge is not defined

Help!, im creating a bot for discord and i put it a prefix, so the error comes when i want to use a command how "(a.richembed)" in discord in the terminal of VSC I get the error "ReferenceError: mesagge is not defined" and i dont know how to fix it, please help me!, heres my code
const Discord = require("discord.js");
const client = new Discord.Client();
let prefix = "a."
client.on("ready", () => {
console.log("Ready to give Atis");
});
client.on("message", (message) => {
if(message.content.startsWith("ATIS JTPH")) {
message.channel.send("Information for airport: JTPH--------- Information: Zulu--------- Time: .......... (eg 16:45:00z)--------- Active Runways: 09L, 09R, 27L, 27R--------- WInd: .....#... (eg 360#15)--------- Clouds:Clear--------- Visibility: >20KM--------- Remarks:None--------- Tower Frequency: 121.20--------- Ground Frequency: 121.30--------- Delivert Center: 121.40--------- Center Frequency: 121.50--------- Emergency Frequency 121.60.");
}
if(message.content.startsWith(prefix+ "Help!")){
message.channel.send("Sending the emergency services to you!")
}
if(mesagge.channel.send.startsWith(prefix,"richembed")){
const embed = new Discord.RichEmbed()
.setTitle("What i can do?")
.setAuthor(message.author.username, message.author.displayAvatarURL)
.setColor(0x00AE86)
.setDescription("Well, mainly I'm designed by my creator Carlos and he coded me to be able to give information to the pilots who need it.")
.setFooter("They will ask: Why is that bot there and why does it have those roles? well, very simple, if you say ATIS JTPH I will tell you a few things about the defined airport such as JTPH!", client.user.avatarURL)
.setImage(message.author.displayAvatarURL)
.setThumbnail(message.author.displayAvatarURL)
.setTimestamp()
.setURL("https://github.com/CraterMaik")
.addField("These texts are still configured by my creator, please be patient!.", true)
.addField("These texts are still configured by my creator, please be patient!", true)
.addBlankField(true)
.addField("These texts are still configured by my creator, please be patient!.", true);
message.channel.send(embed)
}
});
client.login("NjM1MTk5NzE1NTUzODM3MDg2.XbO1Sw.mappUgFXIYeqj5_FgYFQ30TBDto")
Its a typo you typed mesagge instead of message

Slack node js program running session shut down

Sorry to disturb. I am programming a Slack robot to reply user message by using the API
In the morning, it works totally okay. Then after I returned back from my office it just shut down and show me this error
Jiatongs-MacBook-Pro:news-bot jiatongli$ node index.js
Assertion failed: token must be defined
/Users/jiatongli/Desktop/news-bot/node_modules/vow/lib/vow.js:105
throw e;
^
Error: not_authed
at _api.then.fail (/Users/jiatongli/Desktop/news-bot/node_modules/slackbots/index.js:46:33)
at Array.<anonymous> (/Users/jiatongli/Desktop/news-bot/node_modules/vow/lib/vow.js:773:56)
at callFns (/Users/jiatongli/Desktop/news-bot/node_modules/vow/lib/vow.js:24:35)
at process._tickCallback (internal/process/next_tick.js:61:11)
Emitted 'error' event at:
at _api.then.fail (/Users/jiatongli/Desktop/news-bot/node_modules/slackbots/index.js:46:19)
at Array.<anonymous> (/Users/jiatongli/Desktop/news-bot/node_modules/vow/lib/vow.js:773:56)
at callFns (/Users/jiatongli/Desktop/news-bot/node_modules/vow/lib/vow.js:24:35)
at process._tickCallback (internal/process/next_tick.js:61:11)
Jiatongs-MacBook-Pro:news-bot jiatongli$
I personally have no idea what is going on because it seems like the program itself do not have bug. What i miss?
Here is the code in my index.js file:
var SlackBot = require("slackbots");
var request = require("request");
var NewsAPI = require("newsapi");
var unirest = require("unirest");
var API_KEY = process.env.API_KEY;
var Slack_API = process.env.Slack_API;
// create a bot
var bot = new SlackBot({
token: Slack_API,
name: "aloha-ai"
});
bot.on("message", msg => {
switch (msg.type) {
case "message":
// we only want to listen to direct messages that come from the user
if (msg.channel[0] === "D" && msg.bot_id === undefined) {
getRandomTechNews(postMessage, msg.user)
}
break
}
})
const postMessage = (message, user) => {
bot.postMessage(user, message, {
as_user: true
});
}
const getRandomTechNews = (callback, user) => {
unirest.get("https://nuzzel-news-v1.p.rapidapi.com/news?count=10&q=product")
.header("X-RapidAPI-Host", "nuzzel-news-v1.p.rapidapi.com")
.header("X-RapidAPI-Key", API_KEY)
.end(function (response) {
var newsJSON = response.body;
var news = "*Viral News* in product : \n\n\n\n";
for (i = 0; i < newsJSON.results.stories.length; i++) {
news += "_Excerpt:_ \n" + ">" + newsJSON.results.stories[i].excerpt + "\n"
news += "_Let's see the article!_ \n" + newsJSON.results.stories[i].url + "\n\n\n"
};
callback(news, user);
});
}
Your error message seems to indicate that your program is not authenticated with the Slack API: Error: not_authed
Since you are retrieving your API key and token from environment variables:
var API_KEY = process.env.API_KEY;
var Slack_API = process.env.Slack_API;
my guess is that you have started a new terminal session where you have not yet set that environment variable, or you are on a different computer where it is not set.
Before running your program, try exporting those variables from the command line:
export API_KEY=<my-api-key>
export Slack_API=<my-token>
If you have security concerns about your API keys showing up in your bash history you can do one of two things (these are examples of things that I do, but there are probably better, safer practices out there):
You can put an empty space before your command [space]export API_KEY=<my-api-key> instead of export API_KEY=<my-api-key>. This will make it so the command does not show up in your history.
You can put your export commands in a separate file called e.g., ~/.secrets and then run the command source ~/.secrets which will run your export commands.
Probably these will give you a sense of security rather than actual security though, since you can just echo the value of the environment variables, but I personally like taking one of these steps as an extra precaution.
i use this answer and can solve it.
Add a bot https://my.slack.com/services/new/bot and put the token
do you get token for your bot from above url:
did you set this ?

Resources