Discord.py bot that executes responses based on specific role [duplicate]
This question already has an answer here:
How to check if a user has a specific role in on_message?
1 answer
My python script:
import discord
TOKEN = 'X'
client = discord.Client()
@client.event
async def on_message(message):
# we do not want the bot to reply to itself
if message.author == client.user:
return
if message.content.startswith('!test'):
msg = "This message is a test".format(message)
await client.send_message(message.channel, msg)
if message.content.startswith('!admin'):
msg = "This command can be executed only as the owner".format(message)
await client.send_message(message.channel, msg)
@client.event
async def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------')
client.run(TOKEN)
For my discord bot I want to make it so that !test can be used by everyone and the bot would respond with "This message is a test". In addition, I want !admin to only be executed by the owner role and the bot would only respond with "This command can be executed only as the owner" or else it will reply with "Sorry you do not have a permission to use this command". How can I achieve this?
python python-3.x bots discord.py
marked as duplicate by Patrick Haugh
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 at 23:39
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
How to check if a user has a specific role in on_message?
1 answer
My python script:
import discord
TOKEN = 'X'
client = discord.Client()
@client.event
async def on_message(message):
# we do not want the bot to reply to itself
if message.author == client.user:
return
if message.content.startswith('!test'):
msg = "This message is a test".format(message)
await client.send_message(message.channel, msg)
if message.content.startswith('!admin'):
msg = "This command can be executed only as the owner".format(message)
await client.send_message(message.channel, msg)
@client.event
async def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------')
client.run(TOKEN)
For my discord bot I want to make it so that !test can be used by everyone and the bot would respond with "This message is a test". In addition, I want !admin to only be executed by the owner role and the bot would only respond with "This command can be executed only as the owner" or else it will reply with "Sorry you do not have a permission to use this command". How can I achieve this?
python python-3.x bots discord.py
marked as duplicate by Patrick Haugh
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 at 23:39
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
What do you know about the owner role? It's id, its name, etc...
– Patrick Haugh
Nov 20 at 20:35
Let me rephrase instead of using the owner role, how would I make it so that the command can only be executed when the user has the role "member"?
– Ajay Shah
Nov 20 at 22:45
add a comment |
This question already has an answer here:
How to check if a user has a specific role in on_message?
1 answer
My python script:
import discord
TOKEN = 'X'
client = discord.Client()
@client.event
async def on_message(message):
# we do not want the bot to reply to itself
if message.author == client.user:
return
if message.content.startswith('!test'):
msg = "This message is a test".format(message)
await client.send_message(message.channel, msg)
if message.content.startswith('!admin'):
msg = "This command can be executed only as the owner".format(message)
await client.send_message(message.channel, msg)
@client.event
async def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------')
client.run(TOKEN)
For my discord bot I want to make it so that !test can be used by everyone and the bot would respond with "This message is a test". In addition, I want !admin to only be executed by the owner role and the bot would only respond with "This command can be executed only as the owner" or else it will reply with "Sorry you do not have a permission to use this command". How can I achieve this?
python python-3.x bots discord.py
This question already has an answer here:
How to check if a user has a specific role in on_message?
1 answer
My python script:
import discord
TOKEN = 'X'
client = discord.Client()
@client.event
async def on_message(message):
# we do not want the bot to reply to itself
if message.author == client.user:
return
if message.content.startswith('!test'):
msg = "This message is a test".format(message)
await client.send_message(message.channel, msg)
if message.content.startswith('!admin'):
msg = "This command can be executed only as the owner".format(message)
await client.send_message(message.channel, msg)
@client.event
async def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------')
client.run(TOKEN)
For my discord bot I want to make it so that !test can be used by everyone and the bot would respond with "This message is a test". In addition, I want !admin to only be executed by the owner role and the bot would only respond with "This command can be executed only as the owner" or else it will reply with "Sorry you do not have a permission to use this command". How can I achieve this?
This question already has an answer here:
How to check if a user has a specific role in on_message?
1 answer
python python-3.x bots discord.py
python python-3.x bots discord.py
asked Nov 20 at 19:47
Ajay Shah
246
246
marked as duplicate by Patrick Haugh
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 at 23:39
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Patrick Haugh
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 at 23:39
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
What do you know about the owner role? It's id, its name, etc...
– Patrick Haugh
Nov 20 at 20:35
Let me rephrase instead of using the owner role, how would I make it so that the command can only be executed when the user has the role "member"?
– Ajay Shah
Nov 20 at 22:45
add a comment |
What do you know about the owner role? It's id, its name, etc...
– Patrick Haugh
Nov 20 at 20:35
Let me rephrase instead of using the owner role, how would I make it so that the command can only be executed when the user has the role "member"?
– Ajay Shah
Nov 20 at 22:45
What do you know about the owner role? It's id, its name, etc...
– Patrick Haugh
Nov 20 at 20:35
What do you know about the owner role? It's id, its name, etc...
– Patrick Haugh
Nov 20 at 20:35
Let me rephrase instead of using the owner role, how would I make it so that the command can only be executed when the user has the role "member"?
– Ajay Shah
Nov 20 at 22:45
Let me rephrase instead of using the owner role, how would I make it so that the command can only be executed when the user has the role "member"?
– Ajay Shah
Nov 20 at 22:45
add a comment |
1 Answer
1
active
oldest
votes
This is how you can check if a message came from a server owner, no roles required:
if message.content.startswith('!admin'):
if (message.author == message.server.owner):
# do stuff
else:
msg = "This command can only be executed by the owner."
await client.send_message(message.channel, msg)
Of course, if you do this, you first need to make sure that private (direct) messages do not reach this statement, as they have no 'server' parameter. That can be done like this:
if (message.channel.type == discord.ChannelType.private):
return
All of this can be found in the discord.py documentation.
Ok lets say that I want !admin to be used by the role "member" how would I make sure the message author is equal to the role "member."
– Ajay Shah
Nov 20 at 22:43
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
This is how you can check if a message came from a server owner, no roles required:
if message.content.startswith('!admin'):
if (message.author == message.server.owner):
# do stuff
else:
msg = "This command can only be executed by the owner."
await client.send_message(message.channel, msg)
Of course, if you do this, you first need to make sure that private (direct) messages do not reach this statement, as they have no 'server' parameter. That can be done like this:
if (message.channel.type == discord.ChannelType.private):
return
All of this can be found in the discord.py documentation.
Ok lets say that I want !admin to be used by the role "member" how would I make sure the message author is equal to the role "member."
– Ajay Shah
Nov 20 at 22:43
add a comment |
This is how you can check if a message came from a server owner, no roles required:
if message.content.startswith('!admin'):
if (message.author == message.server.owner):
# do stuff
else:
msg = "This command can only be executed by the owner."
await client.send_message(message.channel, msg)
Of course, if you do this, you first need to make sure that private (direct) messages do not reach this statement, as they have no 'server' parameter. That can be done like this:
if (message.channel.type == discord.ChannelType.private):
return
All of this can be found in the discord.py documentation.
Ok lets say that I want !admin to be used by the role "member" how would I make sure the message author is equal to the role "member."
– Ajay Shah
Nov 20 at 22:43
add a comment |
This is how you can check if a message came from a server owner, no roles required:
if message.content.startswith('!admin'):
if (message.author == message.server.owner):
# do stuff
else:
msg = "This command can only be executed by the owner."
await client.send_message(message.channel, msg)
Of course, if you do this, you first need to make sure that private (direct) messages do not reach this statement, as they have no 'server' parameter. That can be done like this:
if (message.channel.type == discord.ChannelType.private):
return
All of this can be found in the discord.py documentation.
This is how you can check if a message came from a server owner, no roles required:
if message.content.startswith('!admin'):
if (message.author == message.server.owner):
# do stuff
else:
msg = "This command can only be executed by the owner."
await client.send_message(message.channel, msg)
Of course, if you do this, you first need to make sure that private (direct) messages do not reach this statement, as they have no 'server' parameter. That can be done like this:
if (message.channel.type == discord.ChannelType.private):
return
All of this can be found in the discord.py documentation.
answered Nov 20 at 21:06
Vojtěch Strnad
11
11
Ok lets say that I want !admin to be used by the role "member" how would I make sure the message author is equal to the role "member."
– Ajay Shah
Nov 20 at 22:43
add a comment |
Ok lets say that I want !admin to be used by the role "member" how would I make sure the message author is equal to the role "member."
– Ajay Shah
Nov 20 at 22:43
Ok lets say that I want !admin to be used by the role "member" how would I make sure the message author is equal to the role "member."
– Ajay Shah
Nov 20 at 22:43
Ok lets say that I want !admin to be used by the role "member" how would I make sure the message author is equal to the role "member."
– Ajay Shah
Nov 20 at 22:43
add a comment |
What do you know about the owner role? It's id, its name, etc...
– Patrick Haugh
Nov 20 at 20:35
Let me rephrase instead of using the owner role, how would I make it so that the command can only be executed when the user has the role "member"?
– Ajay Shah
Nov 20 at 22:45