Python Discord机器人,自动将表情添加到链接中
为我的英语道歉 我正在尝试创建一个Discord机器人,如果我们发送一个链接(youtube链接),它只会自动对表情做出反应。如果我们不发送链接,机器人就不必做出反应。 这就是我尝试过的:Python Discord机器人,自动将表情添加到链接中,python,hyperlink,discord,bots,Python,Hyperlink,Discord,Bots,为我的英语道歉 我正在尝试创建一个Discord机器人,如果我们发送一个链接(youtube链接),它只会自动对表情做出反应。如果我们不发送链接,机器人就不必做出反应。 这就是我尝试过的: import discord from discord.ext import commands from discord.ext.commands import Bot import asyncio bot = commands.Bot(command_prefix = '?') @bot.event
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
如果你能帮我,那就太酷了!谢谢:)我不熟悉您正在使用的工具,但您遇到的问题是因为
message
是message
的一个实例,它没有实现方法startswith
。我相信你把它和字符串混淆了。也许您应该在文档中查找属性/属性/方法,该属性/属性/方法为您获取所需的字符串,以便使用该验证。好的,因此我将async def react(message):
和if(message.startswith(“https://”)或(message.startswith(“http://”):
,替换为:prefix=“?”
异步def react(message):
如果prefix+str(message):
自定义表情=[
但新的问题是,即使我们没有在消息的开头加上“?”,机器人仍然会用他的表情做出反应。有什么帮助吗?我终于完成了我的程序,哈哈,我刚刚替换了prefix=“?”
由lien.content.lower()中的if“?”:
实现,感谢您的帮助和时间;)
AttributeError: 'Message' object has no attribute 'startswith'