I have a Discord.js bot, I want it to give new members a role.
I know how to do that HOWEVER I also have rules screening enabled, and as the option states that giving new members a role will completely bypass the rules screening.
How can I give a role automatically WITHOUT skipping rules screening?
There is an optional pending property on Guild Member Objects you can use for checking.
true: Has not accepted
false: Has accepted
If pending isnt on the object, assume false.
This can be found on the discord dev docs
The description of pending is
whether the user has not yet passed the guild's Membership Screening requirements
There is also a second note regarding the "optional" nature.
In GUILD_ events, pending will always be included as true or false. In non GUILD_ events which can only be triggered by non-pending users, pending will not be included.
Which effectively means, if you're given a guild member object, check the value of pending. If it's not there, assume false.
Related
This is my code
activity=discord.Game(name="Padamine", type=1)
Don’t worry, I put it in a #bot.event function. The problem is that my bot don’t put the custom status in his status. Can you help me?
Use change_presence() method to change bot status:
await bot.change_presence(activity=discord.Game("Padamine"))
If it's a static status (a status that won't change), it is recommended to use the activity keyword argument inside the bot constructor. If you want to make a dynamic status (a status that changes every now and then), use #tasks.loop of discord.ext.tasks (you can find more about tasks here)
# depending on what you name your variable, client/bot
client/bot = commands.Bot(command_prefix="yourprefix", activity=discord.Game("Padamine")) # removed type because there is no such key word argument
Also, it is recommended to not use await bot.change_presence() inside your on_ready event, I am mentioning this because many people do it and it's not good:
Discord has a high chance to completely disconnect you during the READY or GUILD_CREATE events (1006 close code) and there is nothing you can do to prevent it. As noted in the docs, on_ready is also triggered multiple times, not just once.
Basically: don't do anything in on_ready. (except printing that it came online obviously)
I'm trying to make commands that are exclusive to the guild's owner, how would i check that? The closest of what i want is the ADMINISTRATOR permission but not owner
D Pardal's answer is 100% correct.
I'm not sure how familiar with the docs you are, but it could be helpful to start getting a feel for how to find things like that from the Discord.js docs. It, at least for me, helps to gain an understanding of just what every object/class they provide does. If you already know this, and just had a bit of a mental block, just ignore this & have a nice day. Otherwise, I'm waiting on a question of my own, so I figured I'd help out with what I know. I invite you to step through the docs at Discord.js.org with me as I explain this to see exactly what I'm talking about. Until recently, I found the Discord.js.org docs crazily complicated and un-understandable, so I'm hoping I can make it a little easier for you, and anyone else down the line, who could benefit from them.
Something to glean from this is that data about members in a guild can be found in the Guild object representing the guild. How do we find that?
Well, the only place we have to start is (probably, assuming your bot just takes in messages and executes commands based on them) the message we take in, we'll call it message. Going to the Discord.JS docs, scrolling through the Classes on the side, eventually we see that there is, in fact, a Message class!
Now we can look and see what data ships with it, which is a wide variety of things that may be useful to you down the road. If we look close enough, the Message obj does have a property that sounds like what we're looking for, Message.Guild! The docs say that property is of of type Guild, & clicking the hyperlink, it takes us to the class definition for a Guild.
According to the definition, a Guild object represents a Guild on discord, so with any luck, we can get some information about things in said guild. Knowing that we're looking for a specific member in the guild, we might be tempted to look into the Guild#members property- and while that could be useful down the line, it doesn't get us
particulaly close to knowing who the owner is, just who all the members are.
Finally, if we scroll a bit further, we see that the Guild Class has a property called Owner, AND ownerID! Depending on what we want, either could be useful. Owner is a GuildMember object, a representation of a user that contains a lot of details (just like how a Guild object is a representation of a guild with lots of info about it). However, if we just need the ID for something like, say, checking the ID of the command sender to the ID of the owner, we can just get the ID property of the owner object.
In an expanded form you could visualize that like such
const guild = message.guild
const ownerID = guild.ownerID
Or condensed like
const ownerID = message.guild.ownerID
If there's anything I can clarify further let me know! I know I couldn't figure out the docs for the longest time, so I hope this helped at least somewhat.
Just use Guild#owner, like this:
msg.member.id === msg.guild.ownerID // Returns true if the message was sent by the guild owner.
I have created a dialog which checks for some Intent and entity to trigger the response, I have also added slots to capture the missing entities. But when user enter the slot value it changes the intent thus causing change in final response. I have tried adding context variable also and deleting it after response but it gets deleted before response and I am getting empty context variable in response.
Like I have added a slot for capturing missing color values in an Intent say 'looking' and color values are like 'I, G, H' and there's also an Intent let's say Goodbye which is also trained for values like 'G or H'. So, when a user fills the slot value with 'G or H' it also overrides the previous intent 'looking' to 'Goodbye' and my final response value changes. What is the best way to handle this kind of flow?
The current intent is based on the latest utterance by the end user. So when someone types in a follow up to a slot, the intent will change and this is intended.
A common confusion is that this impacts the dialog tree. Because when you test it in "Try it out" you see the intent change. Unless your dialog tree is explicitly looking for it after the slot, then it has no impact what-so-ever.
If you do need it to stay the same, then you can send back the intent object in your context. This will disable Watson Assistant from trying to guess the intent.
The danger here is you need to be mindful that what you send back might not reflect what the user has entered. For example, they may ask something that has to trigger the handler of a slot. Doing this will disable that ability.
I have implemented a multi-turn dialog for Alexa. The Help-Intent provides different Help-Texts depending on the state of the dialog. After the User has triggered the HelpIntent and was presented the Help-Text, I want to elicit a specific slot with the ElicitSlotDirective
Now this seems to be not supported, since you can only elicit slots of the current intent, and the HelpIntent does not have slots.
https://github.com/alexa/alexa-skills-kit-sdk-for-nodejs/issues/162
My question now is: How can I return to my multi-turn dialog and elicit a specific slot after the user triggered the HelpIntent?
You can now use intent chaining to elicit a slot from a different Intent. For example:
.addDirective({
type: 'Dialog.ElicitSlot',
slotToElicit: 'drink',
updatedIntent: {
name: 'OrderIntent',
confirmationStatus: 'NONE'
}
})
See this blog post.
The documentation states that:
Implementing the built-in intents is recommended, but optional.
I recommend that you define your own HelpIntent with overlapping utterances to the AMAZON.HelpIntent, but with your needed Slot types.
In this case, your service receives an IntentRequest for MyHelpIntent, even though these phrases overlap with the built-in AMAZON.HelpIntent.
The documentation also states, that this practice is not recommended, because the built-in intent may have a better coverage of sample utterances. It states that it is better practice to extend the built-in Intents. But (stupid enough from Amazon), the HelpIntent does not support Slots. So the only way would be a custom Help Intent.
I don't see a way to use Dialog Directives with the built-in Intents.
Here's a convoluted workaround that might work (there's no straight forward way right now, Nov 2018):
On every loop of the multi-turn dialog save your dialog based intent in the session attributes (the whole intent object, you can use the intent.name as key)
On every triggered intent (even HelpIntent) save the intent name in a lastIntent session attribute (to keep track of the previous intent name)
User triggers help and you're now in the HelpIntent. After you provide your help message append a question in the end that will cause the user to say something that will trigger your dialog based intent again
Do the following steps when you are in the dialog based intent and only if the lastIntent was HelpIntent (the one in the previous step):
Load the most recent intent data from the session attributes and, in it, delete the slot value and resolutions of the slot you want to elicitate (alternatively if you want to start from scratch you can delete the remaining slot values too, up to you)
Replace the current intent with the modified intent of the previous step
Emit a DialogDelegate with the current intent (your model needs to flag the slot you want to elicitate with elicitationRequired set to true)
I am validating with Cake 3 but can't get it working probably.
As the docs says there are two stages of validating:
Before you save your data you will probably want to ensure the data is correct and consistent. In CakePHP we have two stages of validation:
Before request data is converted into entities, validation rules around data types and formatting can be applied.
Before data is saved, domain or application rules can be applied. These rules help ensure that your application’s data remains consistent.
So, if I understand this right, at first validation rules are used when I pass data via newEntity and patchEntity.
After that, the application rules are used when using save or delete.
However, when I am passing data (an array) via newEntity the application rules are never used (buildRules is never called). When using newEntity without passing data, application rules are used!
So, my first question, is it right that not both rules are runned, only one (OR validation rules, OR application rules?). I would expect that first validation rules would be called to check the input, and before saving, ALSO the application rules would be called to check if the entity is valid to the applicaton.
Second question, how should I validate with my API? The actions pass their data via the newEntity method, but I want to check if (for example) the category_id belongs to the same user. Thats typical an application rule I guess?
Thank you very much ;)
Quoting CakePHP documentation:
Validation objects are intended primarily for validating user input, i.e. forms and any other posted request data.
Basically, validation is done when you use newEntity or patchEntity to check that the incoming data is consistent:
You don't have a random string where you should have a number
The user email is of correct format
Standard and confirmation passwords are equals
etc.
Validation is not done when you set field manually:
$user->email = 'not a valid email' ; // no validation check
Basically, validation rules are meant to tell the user « Hey, you did something wrong! ».
Application rules on the other end are always checked when you call save or delete, these may be used for:
Checking uniqueness of a field
Checking that a foreign key exist - There is an Group that correspond to your group_id
etc.
Your first assumption is somehow false because in the following scenario, both validation and application rules are checked:
$article = $this->Articles->newEntity($this->request->data);
$this->Articles->save($article) ;
This part of the documentation explain the difference between the two layers of validation.
Concerning your second question, you should not check that a user has the right to do something in your model, this should be done by your controller, see CakePHP book for more details.