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


Python Client.send_message方法代码示例

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


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

示例1: on_command

# 需要导入模块: from discord import Client [as 别名]
# 或者: from discord.Client import send_message [as 别名]
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,代码行数:32,代码来源:moderate.py

示例2: on_message

# 需要导入模块: from discord import Client [as 别名]
# 或者: from discord.Client import send_message [as 别名]
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,代码行数:28,代码来源:moderate.py

示例3: handle_playing

# 需要导入模块: from discord import Client [as 别名]
# 或者: from discord.Client import send_message [as 别名]
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,代码行数:10,代码来源:clientSetup.py

示例4: handle_removeplaying

# 需要导入模块: from discord import Client [as 别名]
# 或者: from discord.Client import send_message [as 别名]
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,代码行数:12,代码来源:clientSetup.py

示例5: handle_write

# 需要导入模块: from discord import Client [as 别名]
# 或者: from discord.Client import send_message [as 别名]
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,代码行数:12,代码来源:clientSetup.py

示例6: on_message

# 需要导入模块: from discord import Client [as 别名]
# 或者: from discord.Client import send_message [as 别名]
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,代码行数:52,代码来源:alias.py

示例7: on_command

# 需要导入模块: from discord import Client [as 别名]
# 或者: from discord.Client import send_message [as 别名]
def on_command(client: discord.Client, message: discord.Message, args: list):
    if args[0] == "!wordsearch":
        word = None
        if len(args) > 1:
            if args[1] == "auto":
                count = 1

                if len(args) > 2:
                    try:
                        count = int(args[2])
                    except ValueError:
                        pass

                word = yield from auto_word(count)

        # Start the wordsearch if there are none active in the channel
        # (starting includes includes waiting for a word from the user)
        if message.channel.id not in wordsearch:
            client.loop.create_task(start_wordsearch(client,
                                                     channel=message.channel,
                                                     host=message.author,
                                                     word=word))

            if not word:
                m = "Waiting for {0.mention} to choose a word!".format(message.author)
            else:
                m = None
        else:
            m = "A wordsearch is already active in this channel!"

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

示例8: cmd_help

# 需要导入模块: from discord import Client [as 别名]
# 或者: from discord.Client import send_message [as 别名]
def cmd_help(client: discord.Client, message: discord.Message,
             command: str.lower) -> cmd_help_noargs:
    """ Display commands or their usage and description. """
    usage, desc = "", ""

    for plugin in client.plugins.values():
        command_func = get_command(plugin, command)

        if not command_func:
            continue

        usage = plugin.commands[command]
        if command_func.__doc__:
            desc = command_func.__doc__.strip()
        else:
            desc = "Undocumented."

        # Notify the user when a command is owner specific
        if getattr(command_func, "__owner__", False):
            desc += "\n**Only the bot owner can execute this command.**"

    if usage:
        m = "**Usage**: ```{}``` **Description**: {}".format(usage, desc)
    else:
        m = "Command `{}` does not exist.".format(command)

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

示例9: on_command

# 需要导入模块: from discord import Client [as 别名]
# 或者: from discord.Client import send_message [as 别名]
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,代码行数:61,代码来源:twitch.py

示例10: cmd_game

# 需要导入模块: from discord import Client [as 别名]
# 或者: from discord.Client import send_message [as 别名]
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,代码行数:12,代码来源:builtin.py

示例11: notify_pp

# 需要导入模块: from discord import Client [as 别名]
# 或者: from discord.Client import send_message [as 别名]
def notify_pp(client: discord.Client):
    """ Notify any differences in pp and post the scores + rank/pp gained. """
    for member_id, data in osu_tracking.items():
        # Only update pp when there is actually a difference
        if "old" not in data:
            continue

        old, new = data["old"], data["new"]

        # At this point, there is a difference in pp and we want to notify this
        pp_diff = get_diff(old, new, "pp_raw")

        # There is no difference in pp, therefore we move on to the next member
        if pp_diff == 0:
            continue

        # If the difference is too small, move on
        if pp_threshold > pp_diff > pp_threshold * -1:
            continue

        rank_diff = get_diff(old, new, "pp_rank") * -1
        country_rank_diff = get_diff(old, new, "pp_country_rank") * -1
        accuracy_diff = get_diff(old, new, "accuracy")  # Percent points difference

        # Since the user got pp they probably have a new score in their own top 100
        # If there is a score, there is also a beatmap
        score = yield from get_new_score(member_id)
        member = data["member"]
        mode = get_mode(member_id)

        # If a new score was found, format the score
        if score:
            beatmap_search = yield from api.get_beatmaps(b=int(score["beatmap_id"]))
            beatmap = api.lookup_beatmap(beatmap_search)
            scoreboard_rank = api.rank_from_events(new["events"], score["beatmap_id"])
            m = "{} (`{}`) ".format(member.mention, new["username"]) + \
                format_new_score(mode, score, beatmap, scoreboard_rank) + "\n"

        # There was not enough pp to get a top score, so add the name without mention
        else:
            m = "**{}** " + "(`{}`) ".format(new["username"])

        # Always add the difference in pp along with the ranks
        m += format_user_diff(mode, pp_diff, rank_diff, country_rank_diff, accuracy_diff, old["country"], new)

        # Send the message to all servers
        for server in client.servers:
            if member in server.members:
                channel = get_notify_channel(server)

                # Add the display name in this server when we don't mention
                if not score:
                    m = m.format(member.display_name)

                yield from client.send_message(channel, m)
开发者ID:xZwop,项目名称:PCBOT,代码行数:57,代码来源:osu.py

示例12: cmd_help_noargs

# 需要导入模块: from discord import Client [as 别名]
# 或者: from discord.Client import send_message [as 别名]
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,代码行数:13,代码来源:builtin.py

示例13: cmd_eval

# 需要导入模块: from discord import Client [as 别名]
# 或者: from discord.Client import send_message [as 别名]
def cmd_eval(client: discord.Client, message: discord.Message,
             code: Annotate.Content):
    """ Evaluate an expression. """
    script = get_formatted_code(code)

    try:
        result = eval(script, globals(), locals())
    except Exception as e:
        result = format_exception(e)

    yield from client.send_message(message.channel, "**Result:** \n```{}\n```".format(result))
开发者ID:EdwardBetts,项目名称:PCBOT,代码行数:13,代码来源:builtin.py

示例14: cmd_lambda

# 需要导入模块: from discord import Client [as 别名]
# 或者: from discord.Client import send_message [as 别名]
def cmd_lambda(client: discord.Client, message: discord.Message,
               option: str.lower, trigger: str.lower, code: Annotate.Content="") -> cmd_lambda_noargs:
    """  """
    m = "Command `{}` ".format(trigger)

    if option == "add":
        if code:
            script = get_formatted_code(code)

            if trigger not in lambdas.data:
                lambdas.data[trigger] = script
                lambdas.save()
                m += "set."
            else:
                m += "already exists."
        else:
            m = ""
    elif option == "remove":
        if trigger in lambdas.data:
            lambdas.data.pop(trigger)
            lambdas.save()
            m += "removed."
        else:
            m += "does not exist."
    elif option == "enable":
        if trigger in lambda_blacklist:
            lambda_blacklist.remove(trigger)
            lambdas.save()
            m += "enabled."
        else:
            if trigger in lambdas.data:
                m += "is already enabled."
            else:
                m += "does not exist."
    elif option == "disable":
        if trigger not in lambda_blacklist:
            lambda_blacklist.append(trigger)
            lambdas.save()
            m += "disabled."
        else:
            if trigger in lambdas.data:
                m += "is already disabled."
            else:
                m += "does not exist."
    elif option == "source":
        if trigger in lambdas.data:
            m = "Source for {}: \n{}".format(trigger, lambdas.data[trigger])
        else:
            m += "does not exist."
    else:
        m = ""

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

示例15: on_command

# 需要导入模块: from discord import Client [as 别名]
# 或者: from discord.Client import send_message [as 别名]
def on_command(client: discord.Client, message: discord.Message, args: list):
    if args[0].lower() == "!roulette":
        if message.channel.id not in started:
            started.append(message.channel.id)
            num = 6

            if len(args) > 1:
                try:
                    num = int(args[1])
                except ValueError:
                    num = 6

            if num < 1:
                num = 6

            roulette = Roulette(client, message, num)

            yield from roulette.start()
        else:
            yield from client.send_message(message.channel, "**This channel is already playing.**")

    if args[0].lower() == "!hotpotato":
        if message.channel.id not in started:
            started.append(message.channel.id)
            num = 4

            if len(args) > 1:
                try:
                    num = int(args[1])
                except ValueError:
                    num = 4

            if num < 1:
                num = 4

            hot_potato = HotPotato(client, message, num)

            yield from hot_potato.start()
        else:
            yield from client.send_message(message.channel, "**This channel is already playing.**")
开发者ID:EdwardBetts,项目名称:PCBOT,代码行数:42,代码来源:roulette.py


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