Sending messages#

This document holds information regarding shilling with message objects.

Guild types#

Before you start sending any messages you need to define a GUILD / USER. object. The GUILD objects represents Discord servers with text/voice channels and it can hold TextMESSAGE and VoiceMESSAGE messages, while USER represents a single user on Discord and can hold DirectMESSAGE messages. For more information about how to use GUILD / USER click on them.

Guilds can be passed to the framework at startup, see Quickstart (server_list) for more info.

Message types#

Periodic messages can be represented with instances of xMESSAGE classes, where x represents the channel type. The channel logic is merged with the message logic which is why there are 3 message classes you can create instances from. These classes accept different parameters but still have some in common:

  • start_period - If not None, represents bottom range of randomized period

  • end_period - If start_period is not None, this represents upper range of randomized period, if start_period is None, represents fixed sending period.

  • data (varies on message types) - data that is actually send to Discord.

  • start_in - Defines when the message should be first shilled.

  • remove_after - Defines when the message should be removed from Discord.

For more information about these, see TextMESSAGE, VoiceMESSAGE, DirectMESSAGE.

Text messages#

To periodically send text messages you’ll have to use either TextMESSAGE for sending to text channels inside the guild or DirectMESSAGE for sending to user’s private DM. To add these messages to the guild, set the GUILD / USER’s messages parameter to a table that has the message objects inside.

Listing 5 TextMESSAGE example - normal text (string)#
from datetime import timedelta
import  daf

guilds = [
    daf.GUILD(
        snowflake=123456789,    # ID of server (guild) or a discord.Guild object
        messages=[              # List MESSAGE objects
            daf.TextMESSAGE(
                              start_period=None,                # If None, messages will be send on a fixed period (end period)
                              end_period=timedelta(seconds=15), # If start_period is None, it dictates the fixed sending period,
                                                                # If start period is defined, it dictates the maximum limit of randomized period
                              data="First message",             # Data you want to sent to the function (Can be of types : str, embed, file, list of types to the left
                                                                # or function that returns any of above types(or returns None if you don't have any data to send yet), 
                                                                # where if you pass a function you need to use the daf.FUNCTION decorator on top of it ).
                              channels=[123456789],             # List of ids of all the channels you want this message to be sent into or discord channel Objects
                              mode="send",                      # "send" will send a new message every time, "edit" will edit the previous message, "clear-send" will delete
                                                                # the previous message and then send a new one
                              start_in=timedelta(seconds=0),    # Delay before shilling start
                              remove_after=None                 # Remove the message never or after n-times, after specific date or after timedelta
                              ),
            daf.TextMESSAGE(start_period=5, end_period=timedelta(seconds=10), data="Second Message", channels=[12345], mode="send", start_in=timedelta(seconds=0))  
        ],
        logging=True,           # Generate file log of sent messages (and failed attempts) for this server 
        remove_after=None       # Never stop shilling to this guild
    )
]
                                     
############################################################################################

daf.run(
        token="DNASNDANDASKJNDAKSJDNASKJDNASKJNSDSAKDNAKLSNDSKAJDN",        
        is_user=False,
        server_list=guilds,
    )
Listing 6 DirectMESSAGE example - normal text (string)#
from datetime import timedelta
import daf, secret



############################################################################################
#                               GUILD MESSAGES DEFINITION                                  #
############################################################################################

guilds = [
    daf.USER(
        user_id=123456789,  # ID of server (guild) or a discord.Guild object
        messages=[          # List MESSAGE objects
            daf.DirectMESSAGE(
                              start_period=None,                # If None, messages will be send on a fixed period (end period)
                              end_period=timedelta(seconds=15), # If start_period is None, it dictates the fixed sending period,
                                                                # If start period is defined, it dictates the maximum limit of randomized period
                              data="First message",             # Data you want to sent to the function (Can be of types : str, embed, file, list of types to the left
                                                                # or function that returns any of above types(or returns None if you don't have any data to send yet), 
                                                                # where if you pass a function you need to use the daf.FUNCTION decorator on top of it ).
                              mode="send",                      # "send" will send a new message every time, "edit" will edit the previous message, "clear-send" will delete
                                                                # the previous message and then send a new one
                              start_in=timedelta(seconds=0),    # Start sending now (True) or wait until period
                              remove_after=None                 # Remove the message never or after n-times, after specific date or after timedelta
                              ),
        ],
        logging=True,       # Generate file log of sent messages (and failed attempts) for this user
        remove_after=None   # When to remove the guild and it's message from the shilling list
    )
]
                                     
############################################################################################

daf.run(token=secret.C_TOKEN,        
        server_list=guilds,
        is_user=False)

Voice messages#

Shilling an audio message requires VoiceMESSAGE objects. You can only stream audio to guilds, users(direct messages) are not supported. You can either stream a fixed audio file or a youtube video, both thru daf.dtypes.AUDIO object.

Listing 7 VoiceMESSAGE example - audio file#
import  daf, secret
from datetime import timedelta
from daf import discord


some_audio_file = daf.AUDIO("VoiceMessage.mp3")

guilds = [
    daf.GUILD(
        snowflake=123456789,    # ID of server (guild) or a discord.Guild object or a discord.Guild object
        messages=[              # List MESSAGE objects 
            daf.VoiceMESSAGE(
                              start_period=None,                # If None, messages will be send on a fixed period (end period)
                              end_period=timedelta(seconds=15), # If start_period is None, it dictates the fixed sending period,
                                                                # If start period is defined, it dictates the maximum limit of randomized period
                              data=some_audio_file,             # Data parameter
                              channels=[123456789],             # List of channel ids or discord.VoiceChannel objects
                              volume=50,                        # The volume (0-100%) at which to play the audio
                              start_in=timedelta(seconds=0),    # Start sending now (True) or wait until period
                              remove_after=None                 # Remove the message never or after n-times, after specific date or after timedelta
                              ),  
        ],
        logging=True,           # Generate file log of sent messages (and failed attempts) for this server 
        remove_after=None       # When to remove the guild and it's message from the shilling list
    )
]

############################################################################################

daf.run(token=secret.C_TOKEN,        
        server_list=guilds,
        is_user=False)