如何将机器人提及设置为机器人前缀? (discord.py)
How do I set bot mention as a bot prefix? (discord.py)
我将我的机器人设置为能够拥有自定义前缀,现在我希望我的机器人能够在有人提到它时做出响应。当有人 @bot
或 @bot help
.
时它应该响应
def get_prefix(client, message):
with open('prefixes.json', 'r') as f: ##we open and read the prefixes.json, assuming it's in the same file
prefixes = json.load(f) #load the json as prefixes
return prefixes[str(message.guild.id)] #recieve the prefix for the guild id given
client = commands.Bot(
command_prefix= (get_prefix),
intents = intents
)
我知道了。
def get_prefix(client, message):
with open('prefixes.json', 'r') as f: ##we open and read the prefixes.json, assuming it's in the same file
prefixes = json.load(f) #load the json as prefixes
prefix = prefixes[str(message.guild.id)]
return when_mentioned_or(*prefix)(client, message) #recieve the prefix for the guild id given
client = commands.Bot(
command_prefix= (get_prefix),
intents = intents
)
@client.event
async def on_message(message):
mention = f'<@!{client.user.id}>'
if message.content == mention:
with open('prefixes.json', 'r') as f: ##we open and read the prefixes.json, assuming it's in the same file
prefixes = json.load(f) #load the json as prefixes
prefix = prefixes[str(message.guild.id)]
await message.channel.send(f"You called? My prefix for this server is `{prefix}`. Admins can change it by using `{prefix}changeprefix <new prefix>`")
await client.process_commands(message)
好的,根据@Bruce21,我得到了你想问的问题,这是一个很长的方法,它没有像 @bot help
这样的响应。我有一个简单的方法。
尝试:client = commands.Bot(command_prefix= when_mentioned_or(get_prefix), intents = intents)
我将我的机器人设置为能够拥有自定义前缀,现在我希望我的机器人能够在有人提到它时做出响应。当有人 @bot
或 @bot help
.
def get_prefix(client, message):
with open('prefixes.json', 'r') as f: ##we open and read the prefixes.json, assuming it's in the same file
prefixes = json.load(f) #load the json as prefixes
return prefixes[str(message.guild.id)] #recieve the prefix for the guild id given
client = commands.Bot(
command_prefix= (get_prefix),
intents = intents
)
我知道了。
def get_prefix(client, message):
with open('prefixes.json', 'r') as f: ##we open and read the prefixes.json, assuming it's in the same file
prefixes = json.load(f) #load the json as prefixes
prefix = prefixes[str(message.guild.id)]
return when_mentioned_or(*prefix)(client, message) #recieve the prefix for the guild id given
client = commands.Bot(
command_prefix= (get_prefix),
intents = intents
)
@client.event
async def on_message(message):
mention = f'<@!{client.user.id}>'
if message.content == mention:
with open('prefixes.json', 'r') as f: ##we open and read the prefixes.json, assuming it's in the same file
prefixes = json.load(f) #load the json as prefixes
prefix = prefixes[str(message.guild.id)]
await message.channel.send(f"You called? My prefix for this server is `{prefix}`. Admins can change it by using `{prefix}changeprefix <new prefix>`")
await client.process_commands(message)
好的,根据@Bruce21,我得到了你想问的问题,这是一个很长的方法,它没有像 @bot help
这样的响应。我有一个简单的方法。
尝试:client = commands.Bot(command_prefix= when_mentioned_or(get_prefix), intents = intents)