So what I am trying to do here is when the command is used, the new channel is created, then the user mentions the channel and puts their word, then the hangman is sent within the channel they mentioned. But I get lost cause rn it's running everything at once, how do I make it listen for a new "command"?
const { hangman } = require('reconlx')
module.exports = {
name : 'hangman',
description: "Wanna play hangman?",
aliases: ['hang'],
execute(client, message, args, Discord) {
if(!message.member.hasPermission("MANAGE_MESSAGES")) return message.channel.send('You need manage messages permission.')
const channel = message.mentions.channels.first() || message.guild.channels.cache.get(args[0])
message.guild.channels.create(`HangMan`, {
type: 'text',
permissionOverwrites: [
{
id: message.guild.id,
deny: ['VIEW_CHANNEL']
},
{
id: message.author.id,
allow: ['VIEW_CHANNEL', 'SEND_MESSAGES', 'ADD_REACTIONS', 'ATTACH_FILES']
}
]
}).then(async channel => {
channel.send("Please mention a channel, then add your word. It should look something like this `#the game channel (your word)`")
message.reply(`Scroll to the very top of the server to add your word! <#${channel.id}>`)
})
if(message.content.includes('#')) {
message.reply('Hangman has started!')};
if(!channel) return message.channel.send('Please specify a channel')
const word = args.slice(1).join(" ")
if(!word) return message.channel.send('Please specify a word to guess.')
const hang = new hangman({
message: message,
word: word,
client: client,
channelID: channel.id,
})
hang.start();
}
}
Related
So I want to make it so that every time a new ticket is made it will add a number example: ticket-1 | ticket-2 | ticket-3, ect. And then I want the bot to send the channel in a chat
module.exports = {
data: {
name: `GT1`
},
async execute(interaction, client, message) {
const guild = client.guilds.cache.get("1057116059750117426");
const ticketId = Math.floor(Math.random() * 9000);
await guild.channels.create({
name: `TICKET-${ticketId}`,
parent: '1057370813357109308',
})
interaction.reply({ephemeral: true, content: `Your ticket has been submited \n You can view it here -> ${guild.channels.id}` });
}
}
What you need is a way to persist data after every command. This would require some sort of data storage. I've listed a few options below:
Use a database, (On the discord.js guide they recommend using an ORM)
Store the files in a JSON object on your file system.
Here is an example for 2:
module.exports = {
data: {
name: 'GT1',
},
async execute(interaction, client, message) {
const guild = client.guilds.cache.get('1057116059750117426');
const storageBuffer = fs.readFileSync('./storage.json'); // you will input your file path here.
const storageData = JSON.parse(storageBuffer.toString());
storageData.ticket_id++; // adds one to the ticket number?
const ticketId = storageData.ticket_id;
await guild.channels.create({
name: `TICKET-${ticketId}`,
parent: '1057370813357109308',
});
interaction.reply({
ephemeral: true,
content: `Your ticket has been submited \n You can view it here -> ${guild.channels.id}`,
});
fs.writeFileSync('./storage.json', JSON.stringify(storageData)); // updates the data to your storage file
},
};
You will need to create the json file before using it.
storage.json
{
ticket_id: 0
}
As for sending to a channel you can take a look at this: https://discord.js.org/#/docs/main/stable/class/Interaction?scrollTo=channel
I have a command in which one user virtually kisses another
The output is a message #User1 kissed #User2
But I want that instead of tags on the user, only names were written, like this so that it was user1 kissed user2
In theory, everything should work like this
`**${message.author.username}** kissed **${userToKiss.username}**`
But if the name for message.author is defined, then there is none for userToKiss and I end up with this
user1 kissed undefined
How can I get the name for the second user?
const { Command } = require('discord.js-commando');
const Discord = require('discord.js');
module.exports = class KissCommand extends Command {
constructor(client) {
super(client, {
name: 'kiss',
memberName: 'kiss',
group: 'reywl',
description: 'Kiss the mentioned user',
guildOnly: true,
args: [
{
key: 'userToKiss',
prompt: 'Please select the member you want to kiss.',
type: 'member',
default: 'isempty',
wait: 0.0001
}
]
});
}
run(message, { userToKiss }) {
if (userToKiss == 'isempty') {
return message.channel.send('Please select the member you want to kiss.')}
if (userToKiss.id == message.author.id) {
return message.channel.send('You cant kiss yourself!');
}
else {
const embed = new Discord.MessageEmbed()
.setDescription(`**${message.author}** kissed **${userToKiss}**`)
message.channel.send(embed)
}
setTimeout(() => message.delete(), 1000)
}};
For deep explanation for your work, to do this you need to code first about the member, we always do about member and author
Author is for the author itself and the member for your members who are you going to call
I don't know if commando and normal command handlers are the same but here's the code what you wanted.
const member = message.mentions.members.first() //this is the way how you ping a member
${member.user.username} //the word user is the user member
for the author you can only do this
${message.author.username}
You can also ping a member using their Id's
const member = message.guild.members.cache.get(args[0])
${member.user.username}
So the main output is
${message.author.username} kissed ${member.user.username}
This is how it works
const kissed = await message.guild.members.fetch(userToKiss.id);
${kissed.user.username}
How to add multiple embeds to the code below? I am not asking for you to write to code for me I just need some tips and points on how to add embeds. Because I would like to make it so that the new channel is created then you will get 2 or 3 embeds posted to that channel. One embed will have reactions on there and I would like for then the bot to pair 2 random players so they can have a lvl battle again.
if (
guild.channels.cache.find((channel) => channel.name === "t5-battle-channel")
)
return;
if (reaction.emoji.name === "5️⃣") {
let guild = reaction.message.guild;
guild.channels.create("T5 Battle Channel", {
//Creating the channel
type: "text", //Make sure the channel type is text
permissionOverwrites: [
//Set overwrites
{
id: guild.id,
deny: "VIEW_CHANNEL",
},
{
id: "788400016736780338",
allow: ["VIEW_CHANNEL"],
},
],
});
}
if (
guild.channels.cache.find((channel) => channel.name === "t5-battle-channel")
)
return;
if (reaction.emoji.name === "5️⃣") {
let guild = reaction.message.guild;
guild.channels
.create("T5 Battle Channel", {
//Creating the channel
type: "text", //Make sure the channel type is text
permissionOverwrites: [
//Set overwrites
{
id: guild.id,
deny: "VIEW_CHANNEL",
},
{
id: "788400016736780338",
allow: ["VIEW_CHANNEL"],
},
],
})
.then((channel) => {
channel.send(embed).then((embedMessage) => {
embedMessage.react("👍");
embedMessage.react("👎");
});
});
}
let embed = new Discord.MessageEmbed()
.setColor("#0099ff")
.setTitle("⚔️ T5 Battles! ⚔️")
.setDescription(
"Please react with a Thumbs up if you want to be paired with you opponent!"
)
.setTimestamp()
.setFooter("⚔️ 1657 Battles! ⚔️ | ⚔️ Managed by Ukzs⚔️");
I have a ChoicePrompt with two options.
[ {
value: 'credit',
synonyms: ['titanium', 'world', 'credit', 'mastercard'],
},
{
value: 'visaPrepaid',
synonyms: ['platinium', 'visa', 'prepaid', 'prepaid card', 'visa prepaid']
},]
The user can either click on the suggested action or type directly on the textbot "I want a credit card"
I wish to run on a Luis query recognition on this text and extract whether the user wanted a credit or a prepaid card. However, I don't know how to interect that string.
I use a WaterfallDialog to show the prompt
There are a couple different ways to build a ChoicePrompt. I use ChoiceFactory.forChannel() to do so. I'm then using imBack which returns the choice as a user text input. Alternatively, you could do a postBack, which would act as more of a trigger, and capture the sent value.
In my case, since the choice is returned as a user text input, I grab the text value from the activity and send that to LUIS. I'm matching on the Greeting intent which, if successful, then returns the intent found.
Hope of help!
async choiceStep ( stepContext ) {
const stepResult = stepContext.context.activity.text;
if ( stepResult ) {
const message = ChoiceFactory.forChannel(
stepContext.context, [
{ value: 'Hello', action: { type: 'imBack', title: 'Hello', value: 'Hello' } },
{ value: 'What is the date?', action: { type: 'imBack', title: 'What is the date?', value: 'What is the date?' } }
], `Which do you choose?`
);
await stepContext.context.sendActivity( message );
}
return { status: DialogTurnStatus.waiting };
}
async choiceLuisStep ( stepContext ) {
if ( stepContext.context.activity.text ) {
const stepResults = stepContext.context.activity.text;
await stepContext.context.sendActivity( `You said: ${ stepResults }` );
const recognizerResult = await this.recognizer.recognize( stepContext.context );
let intent = await LuisRecognizer.topIntent( recognizerResult );
if ( intent === 'Greeting' ) {
await stepContext.context.sendActivity( `Luis recognized: ${ intent }` );
return stepContext.next();
} else {
await stepContext.context.sendActivity( 'No LUIS intent was found.' );
return stepContext.next();
}
} else {
await stepContext.context.sendActivity( 'Thanks for visiting!' );
return stepContext.next();
}
}
So, I having an issue of sending a DM to a specific person without an author tag, and without a mention of the person. I tried duplicating the mention array:
/*jshint esversion: 6*/
const commando = require('discord.js-commando');
class Msgowner extends commando.Command {
constructor(client) {
super(client, {
name: 'msgowner',
group: 'info',
memberName: 'msgowner',
description: 'Gives rules on mock or legit duels.',
examples: ['ladderrules type'],
});
}
async run(message) {
var user = {
id: '12345',
username: 'Bloodmorphed',
discriminator: '12345',
avatar: 'd510ca3d384a25b55d5ce7f4c259b2d0',
bot: false,
lastMessageID: null,
lastMessage: null,
};
user.send('Test');
}
}
module.exports = Msgowner;
There is a reason why I need to send DMs this way, but I can't seem to figure out how. (The error it gives now is a unknown function). Also replacing id and discriminator with generic numbers, but they are correct in my code.
Try something like this - get the member you're looking for using message.channel.members.find() method:
async run(message) {
// get Collection of members in channel
let members = message.channel.members;
// find specific member in collection - enter user's id in place of '<id number>'
let guildMember = members.find('id', '<id number>');
// send Direct Message to member
guildMember.send('test message');
}
Edit: It looks like it's also possible to find users outside the current channel by doing something like this:
async run(message) {
// get client from message's channel
let client = message.channel.client;
// fetch user via given user id
let user = client.fetchUser('<id number>')
.then(user => {
// once promise returns with user, send user a DM
user.send('Test message');
});
}
Okay, found my answer:
async run(message) {
var user = {
id: '12345,
username: 'Bloodmorphed',
discriminator: '12345',
avatar: 'd510ca3d384a25b55d5ce7f4c259b2d0',
bot: false,
lastMessageID: null,
lastMessage: null,
};
console.log(user);
message.member.user.send('Test');
}
}
module.exports = Msgowner;
EDIT: This was NOT the answer, still looking for one.