Функция & ldquo; скажи & rdquo; выдает AttributeError: объект 'str' не имеет атрибута 'channel' error

Это рабочее решение. Мы можем получить контент с родительским тегом, а затем вырезать родительский тег из вывода.

import re
from lxml import etree

def _tostr_with_tags(parent_element, html_entities=False):
    RE_CUT = r'^<([\w-]+)>(.*)</([\w-]+)>$' 
    content_with_parent = etree.tostring(parent_element)    

    def _replace_html_entities(s):
        RE_ENTITY = r'&#(\d+);'

        def repl(m):
            return unichr(int(m.group(1)))

        replaced = re.sub(RE_ENTITY, repl, s, flags=re.MULTILINE|re.UNICODE)

        return replaced

    if not html_entities:
        content_with_parent = _replace_html_entities(content_with_parent)

    content_with_parent = content_with_parent.strip() # remove 'white' characters on margins

    start_tag, content_without_parent, end_tag = re.findall(RE_CUT, content_with_parent, flags=re.UNICODE|re.MULTILINE|re.DOTALL)[0]

    if start_tag != end_tag:
        raise Exception('Start tag does not match to end tag while getting content with tags.')

    return content_without_parent

parent_element должен иметь тип Element.

Обратите внимание, что если вы хотите текстовый контент (а не html-объекты в тексте), пожалуйста, оставьте параметр html_entities как False.

0
задан Tristo 15 January 2019 в 19:37
поделиться

1 ответ

Вы должны использовать channel.send(), например:

@bot.command()
async def foo(ctx, arg):
    await ctx.send(arg)

Более подробные примеры можно найти по адресу: https://discordpy.readthedocs.io/en/rewrite/ext/commands /commands.html

0
ответ дан PLASMA chicken 15 January 2019 в 19:37
поделиться
Другие вопросы по тегам:

Похожие вопросы: