简体   繁体   English

我有一条错误消息 server_id = ctx.message.guild.id

[英]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.

相关问题 ctx.message.guild 在服务器 discord.py 中返回 None - ctx.message.guild returning None in server discord.py 从 on_message 获取公会 ID - Get guild ID from on_message 为什么我无法使用 ctx.channel.fetch_message(message.id) 从频道获取消息? - Why can't I get a message from a channel using ctx.channel.fetch_message(message.id)? 我试图通过向用户发送 dm 来发送欢迎消息,但我收到“guild_id1 is not defined”错误 - Im trying to make a welcome message by sending a dm to the user but im getting a "guild_id1 is not defined" error 有什么可以从消息或发送消息的频道中找到公会 ID 吗? Discord.py - Is there anything to find the guild id from a message or the channel the message was sent? Discord.py 如果我在dyscord.py 中有message.id,如何删除消息? - How do I delete a message if I have the message.id in dyscord.py? 有没有办法在 on_message 事件中包含 self、message 和 ctx? - Is there a way to have self, message, and ctx in an on_message event? Discord Guild 的直接消息成员返回错误 - Direct Message Members of a Discord Guild returns into an error 当我单击Heroku Postgres时,出现此错误消息{“错误”:{“ id”:“未经授权”,“消息”:“提供的凭据无效”。}} - This error message {“error”:{“id”:“unauthorized”,“message”:“Invalid credentials provided.”}} when I click on Heroku Postgres 为什么我不能在消息中提及(显示 ID) - Why Cant I Mention In Message (It Shows The Id)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM