If the user is not responding back to the bot for a time interval of 2mins,Bot has to throw a default message like "Hey Are you there"..How can it be done .Tried with the all possible approaches,nothing worked.
Bot developed using Microsoft Bot Framework v4 - Coding done using node js. Tried with Setinterval,setTimer,node-cron,smart-timeout and other packages available.
var cron = require('node-cron');
async function getTimers(context) {
cron.schedule('*/2 * * * *', () => {
console.log('running a task every two minutes', context);
return await context.sendActivity("Hey are you there");
});
}
Related
So I have this code:
import { ThirdwebSDK } from "#thirdweb-dev/sdk";
import { ConnectWallet, useAddress } from "#thirdweb-dev/react";
export default function DonationPage() {
let address = useAddress()
async function sendCoins() {
try {
if (selectedCoin == 'eth') {
} else {
const sdk = new ThirdwebSDK("mainnet");
const contract = await sdk.getContract('ADDRESS_TO_USDC_CONTRACT');
await contract.erc20.transferFrom(address || '0x',CORPORATE_WALLET || '0x', donationAmount);
}
} catch (error: any) {
alert(error.message)
}
}
return (<>...</>)
}
So i'm using ConnectWallet button to get address and using TrustWallet for this, and trying to transfer tokens from 'address' to a corporate wallet, with a specified donation amount. However, I receive this error "This action requires a connected wallet to sign the transaction. Please pass a valid signer to the SDK.".
There seems to be no documentation on this online, and ChatGPT won't help either. Does someone know how to fix this?
Also, how to send Eth to CORPORATE_WALLET using Thirdweb?
There seems to be no documentation on this online
Well there is complete documentation on the SDK on ThirdWeb website.
Since you're performing transaction on the contract you cannot initialize the SDK without a private key or signer. Using neither returns read-only contracts
Because you're performing the operations in the frontend, fromSigner method is recommended. Access the user's wallet and call for the signer, use this to initialize the SDK instance with the .fromSigner() method.
fromSigner documentation
ThirdWeb official fromSigner example with React
Also linking documentation for private key method, just in case you wish to approach that way.
I am creating a Discord Bot and I am getting along quite good, however, I am now trying to implement a command for changing the volume of the bot and I can't figure out how to do it. All I am finding on the Internet is for V12 or below, but I am using the new version of discord.js - V13. Here is what I have for playing the music:
const connection = await connect(channel);
const audioPlayer = createAudioPlayer();
const stream = createStream(song.url);
const resource = createAudioResource(stream, {
inputType: StreamType.Arbitrary,
});
stream.on('error', () => playQueue(guild, channel));
connection.subscribe(audioPlayer);
audioPlayer.play(resource);
This all works but does one of you know how to change the volume?
Side question:
I am also trying to make a /seek <time> to jump to any place in the video and neither am I making any progress with that.
I fixed it now, thanks to Leau:
The problem I had was that I was trying to set resource.volume to the value, whereas I actually would have had to do it via resource.volume.setVolume() with the #discordjs/opus package installed and the option on resource for inlineVolume set to true
I'm setting up a cron job to run a bot command that unlocks/locks a channel at a certain time every day. Trying to get the channel returns either undefined or null, depending on how I go about it.
The bot is added to the discord server and is online
require('dotenv').config();
const Discord = require("discord.js");
const client = new Discord.Client();
client.login(process.env.TOKEN);
const chan = client.channels.cache.get("858211703946084352");
console.log(chan);
const channel = client.channels.fetch("858211703946084352").then(res => {
console.log(res);
});
console.log(channel);
When I run it in the console I get
undefined
Promise { <pending> }
null
I have looked at many many examples and solutions, but none seem to resolve my issue
Edit:
bot has admin permissions.
I did the 'right click on channel and copy ID' technique, which matched the ID I got when I used dev tools to examine the element containing the channel name
There is a MEE6 bot in the server so I know bots can send messages
Edit2:
For fun and profit I deleted the app and remade it, same issue
I tried using a channel the MEE6 bot sends to, same issue
Try running this code in the ready event
client.on('ready', () => {
const chan = client.channels.cache.get("858211703946084352");
console.log(chan);
});
I am running VSCode, Nodejs, Nodemailer, and Reactjs in a Windows machine, but I cannot get Nodemailer to send email. According to the instructions in the web, it should work. Finally I did the following: I created two empty folders in both of which I ran node init, installed Nodemailer, and copied the email sending code. In the other folder I also ran create-react-app. Then I edited the files just enough to get the sending code running.
In the first folder it works without problems, but in the folder with React, it does not do anything. Not even the usual following if(error)/else(success) statements get executed, they are just jumped over. However, the code before and after the transporter.sendMail (or .verify) part are executed... Anyone know why this happens or how to fix it?
This is the code I run in both cra and the non-cra folders:
const nodemailer = require("nodemailer");
const SendEmail = message => {
const transporter = nodemailer.createTransport({
service: "Gmail",
auth: {
user: "from#gmail.com",
pass: "xxxxxxxx"
}
});
transporter.verify(function(error) {
if (error) {
console.log(error);
} else {
console.log("Server is ready to take our messages");
}
});
const mailOptions = {
from: "from#gmail.com",
to: "to#gmail.com",
subject: "Subject",
text: message,
html: "<b>Html</b>"
};
transporter.sendMail(mailOptions, (err, info) => {
if (err) console.log(err);
else console.log(info.response);
});
};
module.exports = SendEmail;
Tim
Gmail has spam filter to prevent spam, so most probably, you may get it pass through sometime and not most time without proper configuration.
and it is not a good idea to send your email in your client app, such as react. Since everyone can access to your email and password to do nasty thing, which is not really a good idea.
Best practice is to request your node server to send mail.
Other than, I noticed that you used gmail to do that. There are some free mail fake stmp server that you can do spamming without the mail provider to flag you as spam user. Such as mailTrap, if you are just interested to test, is react able to send email, try it with mailtrap. I never do it, but still it is better than using your own email provider, as they might have filter rules about it, could be the reason, you are not able to send it.
I'm using a free trial of Google Cloud and I'm almost halfway through the free credit. I don't know if I'm doing something wrong or if it just costs more than I expected, so I was looking at the pricing and realized I don't understand most of it. I'm just learning and having fun so I don't actually want to spend money (or at least not that much), so anything to help make the free credits last the year would be great :)
https://firebase.google.com/pricing/
What I did with my function is get information from Firebase Database for notifications and then send the notification using Firebase Messaging. Here's the code, if it helps.
'use strict';
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.sendNotifications = functions.database.ref('/Notifications/{pushID}/title')
.onWrite(event => {
if (!event.data.exists())
return;
event.data.ref.parent.once('value').then(function(dataSnapshot){
// Grab the eventName and the message
const title = dataSnapshot.child('title').val();
const message = dataSnapshot.child('message').val();
const recipients = dataSnapshot.child('recipients').val();
const tag = dataSnapshot.child('tag').val();
const payload = {
notification:{
title: title,
body: message,
tag: tag,
color: "#51E0F5",
sound: 'default'
},
};
const options = {
priority: 'high',
collapseKey: 'chat',
timeToLive: 3600 // 6 days
};
// Get rid of this Notification in Firebase
event.data.ref.parent.remove();
// Create notification
if (recipients != null)
{
return admin.messaging().sendToDevice(recipients, payload, options);
}
else
{
return;
}
});
})
According to the transactions, I used
App Engine Flex Instance RAM: 1932.033 Gibibyte-hours
App Engine Flex Instance Core Hours: 1932.033 Hours
How do I stop using App Engine Flex Instance? What is it? Or is it time to look for a replacement before they start charging my card.
Thank you!
You can stop all instances in flexible app engine by stopping the VERSION. I use this all the time for development - no sense in keeping things running overnight.
Go to your google cloud platform console, select app engine, then select version. Check the version you want to stop, and then click stop at the top. Note that you can't actually DELETE your last version, but you CAN stop it :) This shuts down all instances.
you cannot stop the App Engine Flexible Instance. You will always have one instance running.
Please have a look at the following post
Google Appengine: Budget and Daily Spending Limit not Working
This question is also related to billing and pricing of appengine
Regards
Michael