AttributeError: 'NoneType' object has no attribute 'author'
AttributeError: 'NoneType' object has no attribute 'author'
所以我正在用 discord.py 制作一个不和谐的机器人,并专注于斜杠命令。
我目前在使用建议命令时遇到问题。让我感到困惑的是,如果我不将代码设置为斜杠命令,它可以完美运行,没有任何问题。但由于我的机器人专注于斜线命令,所以不会削减它。
我的斜杠命令代码
@slash.slash(name='suggest',
guild_ids=guild_ids,
description="yas",
options=[
create_option(
name="suggestion",
description="IDK",
option_type=3,
required=True
)
])
async def _suggest(ctx, *, suggestion: str):
await ctx.channel.purge(limit=1)
channel = bot.get_channel(947510790360006707)
suggestEmbed = discord.Embed(colour=0x52b788)
suggestEmbed.set_author(name=f'Suggested by {ctx.message.author}', icon_url = f'{ctx.author.avatar_url}')
suggestEmbed.add_field(name='Suggestion!', value=f'{suggestion}')
message = await channel.send(embed=suggestEmbed)
await message.add_reaction('✅')
await message.add_reaction('❌')
错误:
File "C:\Users\my user\Documents\CODes\HAHAHA\skymist\bot.py", line 134, in _suggest
suggestEmbed.set_author(name=f'Suggested by {ctx.message.author}', icon_url = f'{ctx.author.avatar_url}')
AttributeError: 'NoneType' object has no attribute 'author'
我的导入如果你需要它们
import discord
import os
from discord.ext import commands
from discord_slash import SlashCommand, SlashContext
from discord_slash.utils.manage_commands import create_option
import requests
import json
我认为你应该使用 ctx.author
而不是 ctx.message.author
所以我正在用 discord.py 制作一个不和谐的机器人,并专注于斜杠命令。 我目前在使用建议命令时遇到问题。让我感到困惑的是,如果我不将代码设置为斜杠命令,它可以完美运行,没有任何问题。但由于我的机器人专注于斜线命令,所以不会削减它。 我的斜杠命令代码
@slash.slash(name='suggest',
guild_ids=guild_ids,
description="yas",
options=[
create_option(
name="suggestion",
description="IDK",
option_type=3,
required=True
)
])
async def _suggest(ctx, *, suggestion: str):
await ctx.channel.purge(limit=1)
channel = bot.get_channel(947510790360006707)
suggestEmbed = discord.Embed(colour=0x52b788)
suggestEmbed.set_author(name=f'Suggested by {ctx.message.author}', icon_url = f'{ctx.author.avatar_url}')
suggestEmbed.add_field(name='Suggestion!', value=f'{suggestion}')
message = await channel.send(embed=suggestEmbed)
await message.add_reaction('✅')
await message.add_reaction('❌')
错误:
File "C:\Users\my user\Documents\CODes\HAHAHA\skymist\bot.py", line 134, in _suggest
suggestEmbed.set_author(name=f'Suggested by {ctx.message.author}', icon_url = f'{ctx.author.avatar_url}')
AttributeError: 'NoneType' object has no attribute 'author'
我的导入如果你需要它们
import discord
import os
from discord.ext import commands
from discord_slash import SlashCommand, SlashContext
from discord_slash.utils.manage_commands import create_option
import requests
import json
我认为你应该使用 ctx.author
而不是 ctx.message.author