Skip to content

Instantly share code, notes, and snippets.

@jayktaylor
Created October 3, 2016 15:04
Show Gist options
  • Select an option

  • Save jayktaylor/c18ddef3817c58ad1cbb6018d33790eb to your computer and use it in GitHub Desktop.

Select an option

Save jayktaylor/c18ddef3817c58ad1cbb6018d33790eb to your computer and use it in GitHub Desktop.
MusicBot - Send all command
async def cmd_sendall(self, args, leftover_args):
"""
Usage:
{command_prefix}sendall <message>
Sends a message to all servers the bot is on
"""
if leftover_args:
args = ' '.join([args, *leftover_args])
for s in self.servers:
await self.safe_send_message(s, args)
@xShineyThighx

Copy link
Copy Markdown

I can confirm that it does work, i just added this to my bot. Make sure you're adding it in the proper spot and the spacing is correct.

ghost commented Feb 5, 2017

Copy link
Copy Markdown

It works, but is there a way of only sending those messages to the channels where the bot is binded in?

@rafaelwastaken

Copy link
Copy Markdown

This code sends a message to every channel the bot is binded to. It's probably really bad code since I suck at Python, but it's been working fine for me. let me know if i fucked something up(which I most likely did lol)

    async def cmd_sendall(self, args, leftover_args):
        """
        Usage:
            {command_prefix}sendall <message>
        Sends a message to every channel the bot is binded to.
        """
        chlist = set(self.get_channel(i) for i in self.config.bound_channels if i)
        chlist.discard(None)

        invalids = set()
        invalids.update(c for c in chlist if c.type == discord.ChannelType.voice)

        chlist.difference_update(invalids)
        self.config.bound_channels.difference_update(invalids)
        
        if leftover_args:
            args = ' '.join([args, *leftover_args])
        for s in chlist:
            await self.safe_send_message(s, args)

@max-bromberg

Copy link
Copy Markdown

If it doesn't work for you, be sure that the formatting does NOT use TAB and only uses spaces. (In front of async it must be spaces not tab)

@Cp-Youfy

Cp-Youfy commented Aug 6, 2017

Copy link
Copy Markdown

Hello, where do I put the code?

@max-bromberg

Copy link
Copy Markdown

The code should be in your bot.py file

@itsRems

itsRems commented Nov 5, 2017

Copy link
Copy Markdown

Hey, is there a version of the code wich send messages directly into default text channel, without the bindtochannel option?
Thx.

@EremMc

EremMc commented Nov 10, 2017

Copy link
Copy Markdown

How would I make one that posts in another, specified channel ex:
(in bot channel)
!announce Im cool

(In pre-specified channel)
MusicBot[Bot]
Im cool

How would one go about doing that? I've tried lots of things :/

@max-bromberg

Copy link
Copy Markdown

@EremMc Check out discord.js with NodeJS. Something like that is super easy to do with discord.js.

@johannesfk

johannesfk commented Jan 10, 2018

Copy link
Copy Markdown

I'm getting this weird error in terminal: /Farmer#6858: !sendall this is a test WARNING: Cannot send message to "Farmer's Dev Cave", invalid channel?. The message gets sent to one of the channels the server is one but not the other.

@amit177

amit177 commented Jan 17, 2018

Copy link
Copy Markdown

Code is outdated.
Don't use ^^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment