Functions
Functions are underappreciated. In general, not just in templates. // Rob Pike ; Learning without thought is labor lost; thought without learning is perilous. // Confucius
Preface
Functions are useful in custom commands. There are several kinds of functions in YAGPDB "engine", such as Type Conversion
, String Manipulation
, Math Functions
, Message Functions
, Mentions
, Role Functions
, Current User
, and Miscellaneous Functions
.
Also, there are more functions like database
, Conditional Branching
, Range Action
, and With Action
, all of which can be made into very different commands. Therefore, those functions should not be underappreciated. We should pay more attention in this part.
Preview
Before actually entering to the world of functions, let's try to read the codes here.
Do you understand the codes? This combination of commands contains many kinds of functions like Type Conversion
, String Manipulation
, Math Functions
, Message Functions
, and other functions.
The following is a command for a small lottery. First, It will send a message with a ping of a role to a specific channel when the lottery is going to be drawn. Second, it will use math functions and string manipulation to generate the 5 winning numbers respectively. Third, it will check if the user's number is correct and save the mentions of the winners into a variable. Last, it will send the result to a channel where the starting message was sent.
Command type: Hourly Interval
Guidance
Try to tell the first, the second, the third, and the last part of the command.
Try to find all of the parts that need an
end
after the function.If you have read the contents here, you may be able to read the codes.
Functions won't be hard so long as you actually understand the usage of them. Therefore, reading the examples and try to understand them is recommended.
Last updated
Was this helpful?