Discord机器人仅将表情符号自动添加到链接

时间:2020-10-29 17:51:45

标签: python hyperlink discord bots

道歉我的英语。

如果我们发送链接(YouTube链接),我正在尝试创建一个Discord Bot,它仅会自动与表情符号反应。如果我们不发送链接,则机器人无需做出反应。 这就是我尝试过的:

import discord
from discord.ext import commands
from discord.ext.commands import Bot
import asyncio

bot = commands.Bot(command_prefix = '?')

@bot.event                                                                      #Message when the bot is ready
async def on_ready():
    print ("Wsh frr chuis prêt !")

async def react(message):                                                       #Emojis that have to be added only if the msg starts with "https://" or "http://"
    if (message.startswith("https://")) or (message.startswith("http://")):
        custom_emojis = [
        "<:Kaneki:734573154831433748>"
        ]
        guild_emoji_names = [str(guild_emoji) for guild_emoji in message.guild.emojis]
        for emoji in custom_emojis:
            #print(emoji, guild_emoji_names)
            #print(emoji in guild_emoji_names)
            if emoji in guild_emoji_names:
                await message.add_reaction(emoji)

@bot.event
async def on_message(message):
    if message.channel.id == 734184787241074758:                                #Channel where messages have to be in to work
            await react(message)

bot.run('<Some_token>')          #Bot's token

我认为问题出在第13行。我尝试使用message.startswith(),但出现错误:

AttributeError: 'Message' object has no attribute 'startswith'

如果您能帮助我,那就太好了!谢谢:)

0 个答案:

没有答案