Sending messages (core)#

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) and while the framework is running (see Modifying the shilling list).

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 first be sent.

  • remove_after - Defines when the message the shilling of message should stop (object be removed from framework).

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 7 TextMESSAGE example - normal text (string)#
from datetime import timedelta
import daf
from daf import discord



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

# File object representing file that will be sent
l_file1 = daf.FILE("./Examples/main_send_file.py")
l_file2 = daf.FILE("./Examples/main_send_multiple.py")

## Embedded
l_embed = daf.discord.Embed(
author_name="Developer",
author_icon="https://solarsystem.nasa.gov/system/basic_html_elements/11561_Sun.png",
fields=\
    [
        discord.EmbedField("Test 1", "Hello World", True),
        discord.EmbedField("Test 2", "Hello World 2", True),
        discord.EmbedField("Test 3", "Hello World 3", True),
        discord.EmbedField("No Inline", "This is without inline", False),
        discord.EmbedField("Test 4", "Hello World 4", True),
        discord.EmbedField("Test 5", "Hello World 5", True)
    ]
)

accounts = [
    daf.ACCOUNT( # ACCOUNT 1
        "JJJKHSAJDHKJHDKJ",
        False,
        [
            daf.USER(123456789,
                     [        
                        daf.DirectMESSAGE(None, timedelta(seconds=15), ["Test", l_file1, l_file2, l_embed]),  
                     ],
                     True)
        ]
    ),
    daf.ACCOUNT( # ACCOUNT 2
        token="JJJKHSAJDHKJHDKJ",
        is_user=False,
        servers=[
            daf.USER(
                snowflake=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=["Test", l_file1, l_file2, l_embed], # Data you want to sent to the function (Can be of types : str, embed, file, list of types to the left
                                    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(accounts=accounts)
Listing 8 DirectMESSAGE example - normal text (string)#
from datetime import timedelta
import daf
from daf import discord



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

# File object representing file that will be sent
l_file1 = daf.FILE("./Examples/main_send_file.py")
l_file2 = daf.FILE("./Examples/main_send_multiple.py")

## Embedded
l_embed = daf.discord.Embed(
author_name="Developer",
author_icon="https://solarsystem.nasa.gov/system/basic_html_elements/11561_Sun.png",
fields=\
    [
        discord.EmbedField("Test 1", "Hello World", True),
        discord.EmbedField("Test 2", "Hello World 2", True),
        discord.EmbedField("Test 3", "Hello World 3", True),
        discord.EmbedField("No Inline", "This is without inline", False),
        discord.EmbedField("Test 4", "Hello World 4", True),
        discord.EmbedField("Test 5", "Hello World 5", True)
    ]
)

accounts = [
    daf.ACCOUNT( # ACCOUNT 1
        "JJJKHSAJDHKJHDKJ",
        False,
        [
            daf.USER(123456789,
                     [        
                        daf.DirectMESSAGE(None, timedelta(seconds=15), ["Test", l_file1, l_file2, l_embed]),  
                     ],
                     True)
        ]
    ),
    daf.ACCOUNT( # ACCOUNT 2
        token="JJJKHSAJDHKJHDKJ",
        is_user=False,
        servers=[
            daf.USER(
                snowflake=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=["Test", l_file1, l_file2, l_embed], # Data you want to sent to the function (Can be of types : str, embed, file, list of types to the left
                                    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(accounts=accounts)

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 9 VoiceMESSAGE example - audio file#
from datetime import timedelta
import daf
from daf import discord



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

accounts = [
    daf.ACCOUNT( # ACCOUNT 1
        "JJJKHSAJDHKJHDKJ",
        False,
        [
            daf.GUILD(123456789,
                     [        
                        daf.VoiceMESSAGE(None, timedelta(seconds=15), daf.AUDIO("VoiceMessage.mp3"), [12345, 6789]),  
                     ],
                     True)
        ]
    ),
    daf.ACCOUNT( # ACCOUNT 2
        token="JJJKHSAJDHKJHDKJ",
        is_user=False,
        servers=[
            daf.GUILD(
                snowflake=123456789, # ID of server (guild) 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=[daf.AUDIO("VoiceMessage.mp3")], # Data you want to sent to the function (Can be of types : str, embed, file, list of types to the left
                                    channels=[12323,2313],
                                    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(accounts=accounts)