Skip to content

Setup

Steps to setup

Using discord-together is quite simple.

  • First, import the DiscordTogether constructor
    from discord_together import DiscordTogether
    
  • Next, create a variable to store the class instance. This variable must be defined in a async function, like on_ready()
    @client.event
    async def on_ready():
        client.togetherControl = await DiscordTogether("BOT_TOKEN_HERE")
        # This creates a bot variable. You can also use the global keyword here instead.
    
  • Finally, you can use the create_link function
    @client.command()
    async def start(ctx):
        link = await client.togetherControl.create_link(ctx.author.voice.channel.id, 'youtube')
        await ctx.send(f"Click the blue link!\n{link}")
    

Here are some examples to add further clarity:

within your bot.py file (using dpy 1.7.2)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
from discord.ext import commands
from discord_together import DiscordTogether

client = commands.Bot(command_prefix="~")

@client.event
async def on_ready():
    print(f"Bot logged into {client.user}.")
    client.togetherControl = await DiscordTogether("BOT_TOKEN_HERE")
    # This makes a bot variable that can be used anywhere within your bot's code, even within cogs.

@client.command()
async def start(ctx):
    # Here we consider that the user is already in a VC accessible to the bot.
    link = await client.togetherControl.create_link(ctx.author.voice.channel.id, 'youtube')
    await ctx.send(f"Click the blue link!\n{link}")

client.run("BOT_TOKEN_HERE")

within any cogs

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
from discord.ext import commands
from discord_together import DiscordTogether

class YoutubeTogetherCog(commands.Cog):
    def __init__(self, client):
        self.client = client

    @commands.Cog.listener()
    async def on_ready(self):
        self.togetherControl = await DiscordTogether("BOT_TOKEN_HERE") 
        # Remember to only use this if you haven't already made a bot variable for `togetherControl` in your bot.py file.
        # If you have already declared a bot variable for it, you can use `self.client.togetherControl` to access it's functions

    @commands.command()
    async def start(self, ctx):
        # Here we consider that the user is already in a VC accessible to the bot.
        link = await self.togetherControl.create_link(ctx.author.voice.channel.id, 'youtube')
        await ctx.send(f"Click the blue link!\n{link}")

def setup(client):
    client.add_cog(YoutubeTogetherCog(client))

Info

If your discord.py fork supports it, you can even use client.http.token instead of inputting your actual token string into the DiscordTogether class constructor.

client.togetherControl = await DiscordTogether(client.http.token)

Invite Example

Voila! An invite into the future of Discord

That's an invite created!

Before we continue, let's clarify what we just did:

  • DiscordTogether(token) is used to initialize the DiscordTogether instance. This allows the module to authorize the request with your bot's credentials when sent to Discord's API. It does not interfere any of the bot's properties. The package uses a token rather than just a bot variable to allow support for any fork of discord.py
  • create_link() is the only function within this library. It's purpose is to create an invite link into the application that you entered as an argument. Find more insight into using this method here

That would conclude the quick setup guide for DiscordTogether.

Advisory Note

At least one person needs to click on the BLUE LINK, not the 'Play' button, in order to start the activity. Once the activity is started, people can join by clicking 'Play'.

Multiple people clicking the blue link at once can cause a "Activity Ended" error screen, however it's not a common occurrence.

Back to top