[英]Per server welcome message
so i am trying to make my bot register a guild on a json file when it joins a server so i could try on making a multiple server welc cmds but it wont work can you help me please所以我试图让我的机器人在加入服务器时在 json 文件上注册一个公会,这样我就可以尝试制作一个多服务器的 welc cmds,但它不起作用,你能帮我吗
intents = discord.Intents().all()
fright = commands.Bot(command_prefix="!!", activity = discord.Activity(type=discord.ActivityType.listening, name="discord.gg/antis"), status=discord.Status.do_not_disturb, intents=intents)
@fright.event
async def on_ready():
print('on')
@fright.event
async def on_guild_join(guild):
with open('welcome.json', 'r') as f:
cha = json.load(f)
cha[str(guild.channel.id)] = "test"
with open('welcome.json', 'w') as f:
json.dump(cha, f, indent=4)
It's because in your line of code (2) you have command_prefix = !!这是因为在您的代码行 (2) 中有 command_prefix = !! you need that to be like this
你需要像这样
import os
import discord
from discord.ext import commands, tasks
import json
def get_prefix(client, message):
with open ('welcome.json', 'r') as f:
cha= json.load(f)
return cha[str(message.guild.id)]
intents = discord.Intents(messages = True, guilds = True, reactions = True, members = True, presences = True) #need to go and enable intents in discord developer settings for the bot or else it wont see the user lists
client = commands.Bot(command_prefix = get_prefix, intents=intents, case_insensitive=True)
This makes it more clear for what intents you are calling out, also making it so commands are case sensitive now for the command should look like this这可以更清楚地了解您正在调用的意图,也使得命令现在区分大小写,因为命令应该看起来像这样
@client.event
async def on_guild_join(guild):
with open('welcome.json', 'r') as f:
cha = json.load(f)
cha[str(guild.channel.id)] = "test"
with open('welcome.json', 'w') as f:
json.dump(cha, f, indent=4)
print(f"{guild.name} has invited (BOT_NAME)")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.