在 python 中嵌入 discord 时出现问题,命令提示符和 discord 均无响应
an issue with making a discord embed in python, no responses on command prompt nor discord
我正在尝试制作一些 'fun' 机器人调用的命令,我想嵌入它们。但是它没有吐出任何东西,甚至没有吐出不和谐的错误,也没有吐出命令提示符,让我不知道如何改进代码。我还想实现一种使用成员的方法:commands.Greedy[discord.Members]
代码,这样我就可以找到谁是命令的目标,但我想我需要先解决这个问题。关于如何这样做有什么建议吗?
我也很困惑,因为我使用 .format
和 f
字符串来尝试使用参数,我也尝试使用 message
,但这给了我一个语法错误 'Error 'list' 对象没有属性 'mention''。我真的无法理解有关命令的文档,因为它们并没有真正给出任何实际代码示例,而且我不擅长理解新东西。有人能解决这个问题吗?
from discord.ext import commands
import discord
bot= commands.Bot(command_prefix='0!')
@bot.event
async def on_message(message):
if message.author == bot.user:
return
if message.content.startswith('Sample Text'):
await message.channel.send('Sample Text')
@bot.command()
async def slap(ctx):
embed = discord.Embed(color=0x00ff00, title='OH! Z E S L A P !', description="ooh, that hurt.")
embed.add_field(name="Man behind the slaughter:", value="test")
await ctx.send(embed=embed)
bot.run('token here')```
-During this edit, when I just had the 'bot command' area, It seemed to have functioned still. This makes it even more confusing...
覆盖默认提供的 on_message()
事件会禁止来自 运行 的任何额外命令。要解决此问题,请在 on_message()
活动末尾添加 bot.process_commands(message)
行。
@bot.event
async def on_message(message):
if message.author == bot.user:
return
if message.content.startswith('Sample Text'):
await message.channel.send('Sample Text')
await bot.process_commands(message)
我正在尝试制作一些 'fun' 机器人调用的命令,我想嵌入它们。但是它没有吐出任何东西,甚至没有吐出不和谐的错误,也没有吐出命令提示符,让我不知道如何改进代码。我还想实现一种使用成员的方法:commands.Greedy[discord.Members]
代码,这样我就可以找到谁是命令的目标,但我想我需要先解决这个问题。关于如何这样做有什么建议吗?
我也很困惑,因为我使用 .format
和 f
字符串来尝试使用参数,我也尝试使用 message
,但这给了我一个语法错误 'Error 'list' 对象没有属性 'mention''。我真的无法理解有关命令的文档,因为它们并没有真正给出任何实际代码示例,而且我不擅长理解新东西。有人能解决这个问题吗?
from discord.ext import commands
import discord
bot= commands.Bot(command_prefix='0!')
@bot.event
async def on_message(message):
if message.author == bot.user:
return
if message.content.startswith('Sample Text'):
await message.channel.send('Sample Text')
@bot.command()
async def slap(ctx):
embed = discord.Embed(color=0x00ff00, title='OH! Z E S L A P !', description="ooh, that hurt.")
embed.add_field(name="Man behind the slaughter:", value="test")
await ctx.send(embed=embed)
bot.run('token here')```
-During this edit, when I just had the 'bot command' area, It seemed to have functioned still. This makes it even more confusing...
覆盖默认提供的 on_message()
事件会禁止来自 运行 的任何额外命令。要解决此问题,请在 on_message()
活动末尾添加 bot.process_commands(message)
行。
@bot.event
async def on_message(message):
if message.author == bot.user:
return
if message.content.startswith('Sample Text'):
await message.channel.send('Sample Text')
await bot.process_commands(message)