How to kick on specific message - node.js

I'm trying to auto-kick people with my discord bot when they send an invite link, but message.author.kick() doesn't seem to work. I've also tried other variations of it, like member.kick().
This is my code so far:
client.on('message', message => {
if (message.content.includes('discord.gg/')) {
message.channel.send('Nope');
message.delete(3000);
message.author.kick('posting links');
}
});

.author gives a User object that you can't kick. You have to kick a GuildMember: you can obtain the author's member object by using message.member.
Here is the correction of your code:
client.on('message', message => {
if (message.content.includes('discord.gg/')) {
message.channel.send('Nope');
message.delete(3000);
message.member.kick('posting links');
}
});

Related

discord.js bot doesn't react to message at all

I've been looking for it for a while on old posts couldn't find anything new. Is this code outdated or is there like a work around for this?
client.on('message', message => {
if (message.content === 'test') {
message.author.send('tested1');
}
});
My conclusion is that the bot can't see the message but I do not know how else I could make a command reply

twitch js bot subscription response

I am writing a bot for the twitch platform, and I want to make it respond to users who have subscribed to the channel.
I found USERNOTICE for this in the documentation https://dev.twitch.tv/docs/irc/commands#usernotice
But I didn't quite understand how to use it.
Something like this?
client.on("message", () => {
client.say(config.get('channel'), '/usernotice message');
});
Just call the /usernotice command and it should respond to this subscription message?
It's just difficult to test all this and I would like to have a more or less specific solution.
UPDATE
Also in old documentation I found this code
chatClient.onSub((channel, user) => {
chatClient.say(channel, `Thanks to #${user} for subscribing to the channel!`);
});
chatClient.onResub((channel, user, subInfo) => {
chatClient.say(channel, `Thanks to #${user} for subscribing to the channel for a total of ${subInfo.months} months!`);
});
chatClient.onSubGift((channel, user, subInfo) => {
chatClient.say(channel, `Thanks to ${subInfo.gifter} for gifting a subscription to ${user}!`);
});
But it throws an error - TypeError: client.onSub is not a function
Is there any way to use it now?
chatClient.on('sub', (channel, user) => {
chatClient.say(channel, `Thanks to #${user} for subscribing to the channel!`);
});
On the assumption you are using tmi.js you should be looking at the tmi.js documentation rather than twitch's documentation. This documentation can be located here
in the documentation they have an example for a subscription event which can be found here:
https://github.com/tmijs/docs/blob/gh-pages/_posts/v1.4.2/2019-03-03-Events.md#subscription
client.on("subscription", (channel, username, method, message, userstate) => {
// Do your stuff.
});

How to send welcome message AND load a specific dialog automatically in Microsoft Bot Framework v.3 (Node.js)?

I'm trying both to show a welcome message when my bot starts up and also load a specific dialog. We are using version 3 in the company where I'm working (I know, it's old and not supported).
As far as the welcome message, https://learn.microsoft.com/en-us/azure/bot-service/nodejs/bot-builder-nodejs-handle-conversation-events?view=azure-bot-service-3.0 says to use on conversationUpdate, which works fine, but this seems to be contradicted by https://blog.botframework.com/2018/07/12/how-to-properly-send-a-greeting-message-and-common-issues-from-customers/, which suggests one should not use conversationUpdate, except when using DirectLine, but instead send an event. Is this the final word on the matter? Is there a better way?
I'd also like to load a dialog automatically after the welcome message. How do I do this? Can I access the session during the 'on conversationUpdate' event above and load the dialog directly there? Is there a better way?
Thanks for any help!
It is contradictory, but conversationUpdate is likely your best bet in most situations. However, because channels handle this differently, you should be aware that the result can vary. For direct line, it is a better option to utilize sending events.
An example, in case of need:
bot.on('conversationUpdate', function(message) {
if (message.membersAdded) {
message.membersAdded.forEach(function(identity) {
if (identity.id === message.address.bot.id) {
var reply = new builder.Message()
.address(message.address)
.text("Welcome");
bot.send(reply);
}
});
}
});
For immediately calling a specific dialog, do this:
bot.on('conversationUpdate', function (message) {
if (message.membersAdded) {
message.membersAdded.forEach(function (identity) {
if (identity.id === message.address.bot.id) {
bot.beginDialog(message.address, '/main');
}
});
}
});
bot.dialog('/main', [
function (session, args, next) {
session.send("Glad you could join.");
session.beginDialog('/next');
}
]);
Simply combine the two for sending the welcome message and starting up a dialog.
Hope of help!

Forward DM message to guild channel

I want to make that when my bot receives a direct message, it sends it to a channel in my guild. How do I achieve this?
I do know I have to use if (message.channel.type == "dm") {}, but how do I take what the bot receives and send it to a specific Server in a specific Channel?
If you just want to send the text, just send its content:
client.on("message", msg => {
if (msg.channel.type == "dm") mychannel.send(msg.content); //mychannel is your TextChannel object
});
If you want to make that you can see the author & stuff like that you could use an embed (see how to build & send one here).
If you want to make like it's almost identical to someone's message, you could use a webhook:
guild.fetchWebhooks().then(webhooks => {
let myhook = webhooks.find("placeholder");
client.on("message", msg => {
if (msg.channel.type == "dm") myhook.send(msg.content, {
username: msg.author.username,
avatarURL: msg.author.avatarURL,
});
});
});
Hope this helped, let me know if you have any other question

Chatbot messages do not show up in Facebook Messenger chat heads

I am developing a chatbot for Facebook Messenger using Microsoft Bot Framework. The bot sends the user proactive messages (reminders). Unfortunately, for some reason the messages never show up in a chat head (the Android widget for conversations), nor pop up a chat head if it wasn't present on the screen before. It does happen for other chatbots (Jarvis, for example).
This is the code that sends the reminders:
Reminder.find({ next_reminder: { $lte: new Date() } }, (err, res) => {
if (err !== null) {
return console.error(err);
}
res.forEach(reminder => {
// Build a notification message and address it to user who created the reminder
const msg = new builder.Message().text('...');
bot.beginDialog(reminder.user_address, '*:/sendReminder', {message: msg, nudnik: nudnik});
});
});
};
};
I have also tried bot.send(msg, () => ....) and session.beginDialog('sendReminder', msg). However, there is still no indication from Messenger when the message is received. What could go wrong here?
OK, I figured it out! Apparently, the default notification setting for a Facebook message is not to show a notification. To change it, in NodeJS you should add channel-specific data to the message with the following code:
msg = msg.sourceEvent({
facebook:
{notification_type: 'REGULAR'}
});
You can discover more in official documentation by Microsoft (here and here) and also in this Github discussion.

Resources