I'm building a ticket system that whenever a user react's with the emoji, a channel get's created with him in it and the team that deals with the tickets. My problem is that when I want to display the user's name in the channel through the following code await message.guild.channels.create(``🎫│${reactor}``, {type: 'text',} and reactor is defined by const reactor = reaction.message.guild.members.cache.get(user.id); I get the user's ID in the channel name. My question is if there's a way to name the channel 🎫│User instead of 🎫│ID (with ID I mean the user's Discord ID, not the actual text 'ID').
There's quite a simple solution to your issue, being that you're attempting to use a GuildMember object, instead of a User object.
At the time that I'm writing this (And it will probably stay like this forever), you're not able to get the username of a GuildMember, but would first of all have to convert it into a User object.
This could be very easily done with the following code:
const member = reaction.guild.member(user.id)
const name = member.user.username
message.guild.channels.create(`${name}s ticket`, {
type: 'text'
})
I'd also like to mention that you're not required to add message after reaction when you're trying to get the guild object! You can simply use the reaction variable you've created in your callback and use it to get the guild object using reaction.guild!
Related
I am trying to create a discord bot using node.js. I want the bot to send a welcome message. At the moment I copied the channel_id of the the welcome channel from discord. Though I want to write code to get the id of the welcome channel by its name. (Or if there is another more effective method). Using discord.js v13.
Get the channel from cache by using Guild#channels. That includes a cache property which has all the channels the bot can see in it[1]. Use the find() method on it and compare the name
// remember channel names can only be lowercase and have no spaces
const channel = guild.channels.cache.find(channel => channel.name === "channel-name");
console.log(channel.id)
One drawback here is that multiple channels can have the same name, unlike IDs, which is why people prefer using IDs instead of name or other properties
[1]: All channels are cached by default, so no need to fetch from API
Fetch the channels of the guild and then find in the cache by its name
<Guild>.channels.fetch().then(channels => channels.cache.find(c=> c.name === "channel_name_here"))
Use Guild.channels to get the list of channels in the server, then loop through them using the fetch() method to find a channel with a matching name.
So iam coding an discord bot and i want to get information out of an list that looks like this and this output is in "information = await guild.invites()"
[<Invite code='GZqCe8EF' guild=<Guild id=847546806937059338 name='Testing' shard_id=None chunked=False member_count=2> online=None members=None>, <Invite code='jQ2HeQfx' guild=<Guild id=847546806937059338 name='Testing' shard_id=None chunked=False member_count=2> online=None members=None>]
is it possible to get single things out like guild id or maybe 2 things like name and invite code and is it possible that u can output every line from it like the first invite code and the second one?
To output every invite code, you can use:
for invite in information:
print(invite.code) #invite.code returns the invite code, do whatever you want to do with it
# you can also add invite.guild.name to for the guild name etc
To output only from one invite:
print(information[0].code)
References
invite object with every possible paramenter after .
Yes it is possible, the invites() method returns list of Invite objects. To check what attributes does this object have look here.
to access an attribute you have to do this: InviteObject.{name of attribute}. Example:
for invite in information:
print(invite.guild.id)
It works the same for any discordpy object:
Look for the method that you are using in discordpy docs (In your case invites())
See what does it return (In your case list of Invite objects)
Search for the object (In your case Invite)
How can I get the highest role name of a mentioned member? I tried something like this but it doesn't work. Thanks! :) btw this is a ban command and I need this bc my bot is crashing when someone is trying to ban a user with a higher rank than bot.
if(message.member.hasPermission('BAN_MEMBERS')){
const user = message.mentions.users.first()
console.log(user.roles.highest.name)
if(!user) return console.log("test1")
if(!args[2]) return console.log("test2")
const ddays = args[1]
What you could do is:
Getting a user's highest role:
Get the UserId from the Mention inside of the Message
Get the Cache from the RoleManager of the Guild in which the Message was sent in
(I don't know if the roles in RoleCache are sorted by position, so sort if needed)
Iterate through the roles in RoleCache and check if the UserId is contained inside a specific role
Get the position of the role
Getting the bot's highest role:
Repeat steps 2-5 for your bot (or integrate them within the previous iteration of the RoleCache)
Then compare both numbers and find out if the bot's "role number" is higher than the one of the user's.
Hi all,
I have question about control flow in Dialogflow. Is it possible to control Dialogflow in fullfillment?
Below are my Dialogflow Process.
I created 'Intent1' -> wait for user input about 'Document Type' such as 'Document No.1' or 'Document No.2', etc ...
I created 'Intent2' -> It is follow-up intent of 'Intent1'. It get user input (Training Phrases) such as 'Document No.1' or 'Document No.2' or etc. This 'Intent2' has created parameters for get 'Document Type' such as 'No.1' or 'No.2' from user input.
I created fulfillment 'Inline' for 'Intent2' too. After user input 'No.1' or 'No.2' or etc. I check the parameter value with my Firebase Realtime Database. And then return result message to user for waiting next user input by using ...
agent.add("...some phrase...");
I want to know, is it possible to control Dialogflow in fullfillment?
Such as, if I check 'No.3' does not in by Database, may I send message
"It is not in database" and force process back to 'Intent1'.
But if 'No.1' is in my Database, may I send message "Please input time
to get it?" to user and wait user input at 'Intent3' (follow-up intent
of 'Intent2').
I try to search guide for solving but not found.
Thank in advance
Using Firebase to retrieve data
When using firebase to retrieve data for your dialogflow agent, try not to have any ' business logic' in your databases. Instead, query the database, get the results in your application code (for this example Inline fulfillment), and have your logic there (i.e. did the results come back null or non-null, depending on if it exists in the database). Now, let's get back to your problem at stake.
Implementing a solution
First, you should have code that looks like this to set up the connection between Dialogflow and Firebase.
const admin = require('firebase-admin');
admin.initializeApp({
credential: admin.credential.applicationDefault(),
databaseURL: 'ws://project_name.firebaseio.com/'
});
If you have issues with respect to using firebase-admin, you will need greater permission and check out this out.
Next, when your user says a Document Type to the agent, you query the database based on what you extracted from the user. This extraction is stored in a variable you named when you created parameters in the console. You can name this variable anything; I am going to call this extracted parameter userType. The inline fulfillment code is as follows:
function getDoc(agent){
// userType is what the user responded to you
const response = agent.parameters.userType;
return admin.database().ref('data').once('value').then((snapshot) => {
const type = snapshot.child(response).val();// response is variable so no quotes
if(type!== null){
agent.add(`You chose Document type ${type}`);
}
else{
// type == null indicating the type doesn't exist in the database
agent.add('You gave an invalid type');
}
});
}
If the Document Type the user said to agent exists in your database, then the variable above I called type will be some value (not null). If it is null, then what the user asked for is not in the database, and you can prompt a message to user as a follow up such as, "Your input is invalid."
In your example, if the user asked for No. 3 then response would refer to No. 3 and the type would be null. indicative of the fact No. 3 is not is your database.
Resources:
Video by Axle Web Technologies about the workflow and syntax of connecting Dialogflow to Firebase (highly recommended)
Accessing parameters from inside a fulfillment, by GCP Quickstart
Get data using Firebase, from the Firebase Documentation
I must be missing something because I am fairly sure this should work, since I have used this same method before in a different command in the same bot...
I have a bot that connects to a mysql database. Inside a table in the database that stores the info for a match of a game I'm making, I store the Discord ID's of each player. After pulling those ID's from the table, specifying which one I'd like the user object retrieved for, and trying to use .get() (also attempted to use .find() with a username instead), both result in "undefined"... I have a feeling the bot doesn't find the entire user collection, because when I console.log(client.users), I get Collection [Map] {} So, it looks to be empty? I have also put in the ID itself instead of a variable and it still can't find it. So, I have a feeling the bot just doesn't get the users collection for some reason.
In the below code:
playerIDArray = the player ID's I stored at the start of the match of the game, pulling them from the mysql table. Stored in array format ("player 1's ID" as index 0, "player 2's ID" as index 1, "player 3's ID" as index 2, etc)
playerIndex = the index of the target player in playerIDArray, found in an earlier step before the below code runs, that I know returns what I expect.
const Discord = require('discord.js');
const client = new Discord.Client();
const mysql = require("mysql2/promise");
...
...
var targetUserID = playerIDArray[playerIndex]
var targetUser = client.users.get(targetUserID)
console.log(targetUser)
Each time I run this, I get "undefined" and for the life of me can't figure out why... I just want to retrieve the user group so I can send a message to that user, giving them an opportunity to counter before I modify the mysql table and move cards around that would then need to be immediately altered again to restore what was just removed via a counter card.
I must just be dumb and am missing something but I'm lost as to what to try now... Thanks for any help in advance.
You can only use client.users ( and other discord.js Collections ) after the ready event fired.
So you need to put the code that uses client.users into
client.on('ready', () => { /* CODE */});
ready will be fired after successful client.login('token');.