当前位置: 首页>>代码示例>>Python>>正文


Python discord.Client类代码示例

本文整理汇总了Python中discord.Client的典型用法代码示例。如果您正苦于以下问题:Python Client类的具体用法?Python Client怎么用?Python Client使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Client类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: on_message

def on_message(client: discord.Client, message: discord.Message, args: list):
    if message.channel.is_private:
        return False

    channel = moderate.data.get(message.server.id, {}).get("nsfw-channel")

    if channel:
        # Check if message includes keyword nsfw and a link
        msg = message.content.lower()
        if "nsfw" in msg and ("http://" in msg or "https://" in msg) and not message.channel == channel:
            if message.server.me.permissions_in(message.channel).manage_messages:
                yield from client.delete_message(message)

            nsfw_channel = message.server.get_channel(moderate.data[message.server.id].get("nsfw-channel"))

            if nsfw_channel:
                yield from client.send_message(message.channel, "{}: **Please post NSFW content in {}**".format(
                    message.author.mention, nsfw_channel.mention
                ))
            else:
                yield from client.send_message(message.channel, "{}: **I did not find the specified NSFW channel.** "
                                                                "If you wish to remove this feature, see `!help "
                                                                "nsfwchannel`.".format(message.server.owner.mention))
            return True

    return False
开发者ID:EdwardBetts,项目名称:PCBOT,代码行数:26,代码来源:moderate.py

示例2: on_command

def on_command(client: discord.Client, message: discord.Message, args: list):
    if args[0] == "!nsfwchannel":
        if message.author.permissions_in(message.channel).manage_server:
            m = "Please see `!help nsfwchannel`."
            set_channel = message.server.get_channel(moderate.data.get(message.server.id, {}).get("nsfw-channel"))

            if len(args) > 1:
                if args[1] == "set" and len(args) > 2:
                    if message.channel_mentions:
                        nsfw_channel = message.channel_mentions[0]

                        # Initialize the server moderation
                        if not moderate.data.get(message.server.id):
                            moderate.data[message.server.id] = {}

                        moderate.data[message.server.id]["nsfw-channel"] = nsfw_channel.id
                        moderate.save()
                        m = "Set server NSFW channel to {}".format(nsfw_channel.mention)
                elif args[1] == "remove":
                    if set_channel:
                        moderate.data[message.server.id].pop("nsfw-channel")
                        moderate.save()
                        m = "{0.mention} is no longer the NSFW channel.".format(set_channel)
            else:
                if set_channel:
                    m = "NSFW channel is {0.mention}".format(set_channel)

            yield from client.send_message(message.channel, m)
        else:
            yield from client.send_message(message.channel, "You need `Manage Server` permission to use this command.")
开发者ID:EdwardBetts,项目名称:PCBOT,代码行数:30,代码来源:moderate.py

示例3: __init__

 def __init__(self, config):
     Client.__init__(self)
     self.config = config
     self.commands = []
     for k, v in LoggerBot.__dict__.items():
         if hasattr(v, 'command'):
             self.commands.append(k)
开发者ID:Hornwitser,项目名称:DiscordLogger,代码行数:7,代码来源:bot.py

示例4: on_command

def on_command(client: discord.Client, message: discord.Message, args: list):
    if args[0] == "!twitch":
        m = "Please see `!help twitch`."
        if len(args) > 1:
            # Assign a twitch channel to your name or remove it
            if args[1] == "set":
                if len(args) > 2:
                    twitch_channel = args[2]
                    twitch_channels.data["channels"][message.author.id] = twitch_channel
                    twitch_channels.save()
                    m = "Set your twitch channel to `{}`.".format(twitch_channel)
                else:
                    if message.author.id in twitch_channels.data["channels"]:
                        twitch_channels.data["channels"].pop(message.author.id)
                        twitch_channels.save()
                        m = "Twitch channel unlinked."

            # Return the member's or another member's twitch channel as a link
            elif args[1] == "get":
                if len(args) > 2:
                    member = client.find_member(message.server, args[2])
                else:
                    member = message.author

                if member:
                    # Send the link if member has set a channel
                    if member.id in twitch_channels.data["channels"]:
                        m = "{}'s twitch channel: https://secure.twitch.tv/{}.".format(
                            member.name,
                            twitch_channels.data["channels"][member.id]
                        )
                    else:
                        m = "No twitch channel assigned to {}!".format(member.name)
                else:
                    m = "Found no such member."

            # Set or get the twitch notify channel
            elif args[1] == "notify-channel":
                if message.author.permissions_in(message.channel).manage_server:
                    if len(args) > 2:
                        channel = client.find_channel(message.server, args[2])

                        if channel:
                            twitch_channels.data["notify-channel"] = channel.id
                            twitch_channels.save()
                            m = "Notify channel set to {}.".format(channel.mention)
                    else:
                        if "notify-channel" in twitch_channels.data:
                            twitch_channel = client.get_channel(twitch_channels.data["notify-channel"])
                            if twitch_channel:
                                m = "Twitch notify channel is {}.".format(twitch_channel)
                            else:
                                m = "The twitch notify channel no longer exists!"
                        else:
                            m = "A twitch notify channel has not been set."
                else:
                    m = "You need `Manage Server` to use this command."

        yield from client.send_message(message.channel, m)
开发者ID:EdwardBetts,项目名称:PCBOT,代码行数:59,代码来源:twitch.py

示例5: handle_playing

def handle_playing(c:discord.Client, message:discord.Message, command:list, pref:Preferences):
    if len(command) == 4:
        pref.addGameSaying(command[2], command[3])
        yield from c.send_message(message.channel, 'Done.')
    else:
        yield from c.send_message(message.channel, 'I don\'t get what you are telling me to do.  '
                                                   'Make sure to use quotation marks around the game name'
                                                   ' and the saying')
开发者ID:Tormyst,项目名称:GameNote-Discord,代码行数:8,代码来源:clientSetup.py

示例6: game

def game(client: discord.Client, message: discord.Message, name: Annotate.Content=None):
    """ Stop playing or set game to `name`. """
    yield from client.change_status(discord.Game(name=name, type=0))

    if name:
        yield from client.say(message, "*Set the game to* **{}**.".format(name))
    else:
        yield from client.say(message, "*No longer playing.*")
开发者ID:xZwop,项目名称:PCBOT,代码行数:8,代码来源:builtin.py

示例7: __init__

    def __init__(self, prefix, token):
        Client.__init__(self)
        self.prefix = prefix
        self.token = token
        self.plugins = []
        self.playlist = set()

        self.load_plugins()
开发者ID:Theoretical,项目名称:UselessBot,代码行数:8,代码来源:useless_bot.py

示例8: handle_write

def handle_write(c:discord.Client, message:discord.Message, command:list, pref:Preferences):
    if message.server and len(command) == 3:
        if(command[2] == "here"):
            toSet = message.channel
        elif len(message.channel_mentions) > 0 and message.channel_mentions[0].type == discord.ChannelType.text:
            toSet = message.channel_mentions[0]

        if not pref.addServerChannel(message.server, toSet):
            yield from c.send_message(message.channel, 'Something went wrong while saving the setting.')
        yield from c.send_message(message.channel, 'Ok, I will use {}'.format(toSet))
开发者ID:Tormyst,项目名称:GameNote-Discord,代码行数:10,代码来源:clientSetup.py

示例9: cmd_game

def cmd_game(client: discord.Client, message: discord.Message,
             name: Annotate.Content):
    """  """
    if name:
        m = "Set the game to **{}**.".format(name)
    else:
        m = "No longer playing."

    yield from client.change_status(discord.Game(name=name))
    yield from client.send_message(message.channel, m)
开发者ID:EdwardBetts,项目名称:PCBOT,代码行数:10,代码来源:builtin.py

示例10: handle_removeplaying

def handle_removeplaying(c: discord.Client, message: discord.Message, command: list, pref: Preferences):
    if len(command) == 4:
        if pref.rmGameSaying(command[2], command[3]):
            yield from c.send_message(message.channel, 'Removed.')
        else:
            yield from c.send_message(message.channel, 'Could not remove that.  Check that you wrote it right.')
    else:
        yield from c.send_message(message.channel, 'I don\'t get what you are telling me to do.  '
                                                   'Make sure to use quotation marks around the game name'
                                                   ' and the saying')
开发者ID:Tormyst,项目名称:GameNote-Discord,代码行数:10,代码来源:clientSetup.py

示例11: cmd_help_noargs

def cmd_help_noargs(client: discord.Client, message: discord.Message):
    m = "**Commands:**```"

    for plugin in client.plugins.values():
        if plugin.commands:
            m += "\n" + "\n".join(usage for cmd, usage in plugin.commands.items() if usage and
                                  (not getattr(get_command(plugin, cmd), "__owner__", False) or
                                  client.is_owner(message.author)))

    m += "```\nUse `!help <command>` for command specific help."
    yield from client.send_message(message.channel, m)
开发者ID:EdwardBetts,项目名称:PCBOT,代码行数:11,代码来源:builtin.py

示例12: ping

def ping(client: discord.Client, message: discord.Message):
    """ Tracks the time spent parsing the command and sending a message. """
    # Track the time it took to receive a message and send it.
    start_time = datetime.now()
    first_message = yield from client.say(message, "Pong!")
    stop_time = datetime.now()

    # Edit our message with the tracked time (in ms)
    time_elapsed = (stop_time - start_time).microseconds / 1000
    yield from client.edit_message(first_message,
                                   "Pong! `{elapsed:.4f}ms`".format(elapsed=time_elapsed))
开发者ID:xZwop,项目名称:PCBOT,代码行数:11,代码来源:builtin.py

示例13: disable

def disable(client: discord.Client, message: discord.Message, trigger: str.lower):
    """ Disable a command. """
    # If the specified trigger is not in the blacklist, we add it
    if trigger not in lambda_config.data["blacklist"]:
        lambda_config.data["blacklist"].append(trigger)
        lambda_config.save()
        yield from client.say(message, "Command `{}` disabled.".format(trigger))
    else:
        assert trigger in lambdas.data, "Command `{}` does not exist.".format(trigger)

        # The command exists so surely it must be disabled
        yield from client.say(message, "Command `{}` is already disabled.".format(trigger))
开发者ID:xZwop,项目名称:PCBOT,代码行数:12,代码来源:builtin.py

示例14: import_

def import_(client: discord.Client, message: discord.Message, module: str, attr: str=None):
    """ Import the specified module. Specifying `attr` will act like `from attr import module`. """
    try:
        import_module(module, attr)
    except ImportError:
        yield from client.say(message, "Unable to import `{}`.".format(module))
    except KeyError:
        yield from client.say(message, "Unable to import `{}` from `{}`.".format(attr, module))
    else:
        # There were no errors when importing, so we add the name to our startup imports
        lambda_config.data["imports"].append((module, attr))
        lambda_config.save()
        yield from client.say(message, "Imported and setup `{}` for import.".format(attr or module))
开发者ID:xZwop,项目名称:PCBOT,代码行数:13,代码来源:builtin.py

示例15: on_message

def on_message(client: discord.Client, message: discord.Message, args: list):
    user_id = message.author.id

    # User alias check
    if aliases.data.get(user_id):
        success = False

        user_aliases = aliases.data[user_id]
        for name, command in user_aliases.items():
            execute = False
            msg = message.content

            if not command.get("case-sensitive", False):
                msg = msg.lower()

            if command.get("anywhere", False):
                if name in msg:
                    execute = True
            else:
                if msg.startswith(name):
                    execute = True

            # Add any mentions to the alias
            mention = ""
            if message.mentions:
                mentions = [member.mention for member in message.mentions]
                mention = " =>(" + ", ".join(mentions) + ")"

            if execute:
                if command.get("delete-message", False):
                    if message.server.me.permissions_in(message.channel).manage_messages:
                        asyncio.async(client.delete_message(message))

                asyncio.async(client.send_message(
                    message.channel,
                    "{}{}: {}".format(message.author.mention, mention, command.get("text")))
                )

                success = True

        return success

    # See if the user spelled definitely wrong
    for spelling in ["definately", "definatly", "definantly", "definetly", "definently", "defiantly"]:
        if spelling in message.clean_content:
            yield from client.send_message(message.channel,
                                           "{} http://www.d-e-f-i-n-i-t-e-l-y.com/".format(message.author.mention))
            return True

    return False
开发者ID:EdwardBetts,项目名称:PCBOT,代码行数:50,代码来源:alias.py


注:本文中的discord.Client类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。