discord.Message
has a bunch of attributes, the ones you're asking for are:
So, let's say you're using an on_message
event, to get the guild ID:
async def on_message(message):
guild_id = message.guild.id
To get the channel ID:
async def on_message(message):
channel_id = message.channel.id
If you're using commands, the Context
attributes are the same
guild_id = ctx.guild.id
channel_id = ctx.channel.id
Also these are basics OOP concepts, you should already know that if you're messing with discord bots - my suggestion, learn more python.
Reference:
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…