[英]I have an error message with server_id = ctx.message.guild.id
I have a problem and I can't find a solution.我有一个问题,我找不到解决方案。 When I put
server_id = ctx.message.guild.id
in the following python source code, the terminal shows me:当我将
server_id = ctx.message.guild.id
放在以下 python 源代码中时,终端显示:
nextcord.errors.ApplicationInvokeError: Command raised an exception: AttributeError: 'NoneType' object has no attribute 'guild'
Just because I put my command in /command.只是因为我把我的命令放在 /command 中。
Here is my code:这是我的代码:
@bot.slash_command()
async def name(ctx):
server_id = ctx.message.guild.id
await ctx.send(server_id)
with below imports:具有以下进口:
import discord
from discord.ext import commands
from random import *
import os
from nextcord.ext import *
from nextcord import *
from nextcord.ui import *
I'm waiting for someone to help me and for the problem to be solved.我在等待有人帮助我并解决问题。 Thank you.
谢谢你。
You should decide on one library to use first off, I recommend discord.py, but it's up to you.您应该首先决定使用一个库,我推荐 discord.py,但这取决于您。
Anyways, the problem is that there is no message attached to the context, but you can just do ctx.guild.id
and it will work fine (Assuming you actually have a correct if statement).无论如何,问题是没有消息附加到上下文,但你可以只执行
ctx.guild.id
并且它会正常工作(假设你实际上有一个正确的 if 语句)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.