简体   繁体   中英

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:

nextcord.errors.ApplicationInvokeError: Command raised an exception: AttributeError: 'NoneType' object has no attribute 'guild'

Just because I put my command in /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.

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM